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

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

Issue 13145003: Rewrite std::string("") to std::string(), Linux edition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ugh Created 7 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 | Annotate | Revision Log
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 <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 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 static void ExtractParameters(const std::string& params, 425 static void ExtractParameters(const std::string& params,
426 std::map<std::string, std::string>* result) { 426 std::map<std::string, std::string>* result) {
427 std::vector<std::string> pairs; 427 std::vector<std::string> pairs;
428 base::SplitString(params, '&', &pairs); 428 base::SplitString(params, '&', &pairs);
429 for (size_t i = 0; i < pairs.size(); i++) { 429 for (size_t i = 0; i < pairs.size(); i++) {
430 std::vector<std::string> key_val; 430 std::vector<std::string> key_val;
431 base::SplitString(pairs[i], '=', &key_val); 431 base::SplitString(pairs[i], '=', &key_val);
432 if (!key_val.empty()) { 432 if (!key_val.empty()) {
433 std::string key = key_val[0]; 433 std::string key = key_val[0];
434 EXPECT_TRUE(result->find(key) == result->end()); 434 EXPECT_TRUE(result->find(key) == result->end());
435 (*result)[key] = (key_val.size() == 2) ? key_val[1] : ""; 435 (*result)[key] = (key_val.size() == 2) ? key_val[1] : std::string();
436 } else { 436 } else {
437 NOTREACHED(); 437 NOTREACHED();
438 } 438 }
439 } 439 }
440 } 440 }
441 441
442 static void VerifyQueryAndExtractParameters( 442 static void VerifyQueryAndExtractParameters(
443 const std::string& query, 443 const std::string& query,
444 std::map<std::string, std::string>* result) { 444 std::map<std::string, std::string>* result) {
445 std::map<std::string, std::string> params; 445 std::map<std::string, std::string> params;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 EXPECT_TRUE(ContainsKey(params, "ping")); 630 EXPECT_TRUE(ContainsKey(params, "ping"));
631 } 631 }
632 632
633 void TestUpdateUrlDataEmpty() { 633 void TestUpdateUrlDataEmpty() {
634 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 634 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
635 const std::string version = "1.0"; 635 const std::string version = "1.0";
636 636
637 // Make sure that an empty update URL data string does not cause a ap= 637 // Make sure that an empty update URL data string does not cause a ap=
638 // option to appear in the x= parameter. 638 // option to appear in the x= parameter.
639 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 639 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
640 fetch_data.AddExtension(id, version, &kNeverPingedData, "", ""); 640 fetch_data.AddExtension(
641 id, version, &kNeverPingedData, std::string(), std::string());
641 642
642 std::map<std::string, std::string> params; 643 std::map<std::string, std::string> params;
643 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params); 644 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params);
644 EXPECT_EQ(id, params["id"]); 645 EXPECT_EQ(id, params["id"]);
645 EXPECT_EQ(version, params["v"]); 646 EXPECT_EQ(version, params["v"]);
646 EXPECT_EQ(0U, params.count("ap")); 647 EXPECT_EQ(0U, params.count("ap"));
647 } 648 }
648 649
649 void TestUpdateUrlDataSimple() { 650 void TestUpdateUrlDataSimple() {
650 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 651 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
651 const std::string version = "1.0"; 652 const std::string version = "1.0";
652 653
653 // Make sure that an update URL data string causes an appropriate ap= 654 // Make sure that an update URL data string causes an appropriate ap=
654 // option to appear in the x= parameter. 655 // option to appear in the x= parameter.
655 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 656 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
656 fetch_data.AddExtension(id, version, &kNeverPingedData, "bar", ""); 657 fetch_data.AddExtension(
658 id, version, &kNeverPingedData, "bar", std::string());
657 std::map<std::string, std::string> params; 659 std::map<std::string, std::string> params;
658 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params); 660 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params);
659 EXPECT_EQ(id, params["id"]); 661 EXPECT_EQ(id, params["id"]);
660 EXPECT_EQ(version, params["v"]); 662 EXPECT_EQ(version, params["v"]);
661 EXPECT_EQ("bar", params["ap"]); 663 EXPECT_EQ("bar", params["ap"]);
662 } 664 }
663 665
664 void TestUpdateUrlDataCompound() { 666 void TestUpdateUrlDataCompound() {
665 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 667 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
666 const std::string version = "1.0"; 668 const std::string version = "1.0";
667 669
668 // Make sure that an update URL data string causes an appropriate ap= 670 // Make sure that an update URL data string causes an appropriate ap=
669 // option to appear in the x= parameter. 671 // option to appear in the x= parameter.
670 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 672 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
671 fetch_data.AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c", ""); 673 fetch_data.AddExtension(
674 id, version, &kNeverPingedData, "a=1&b=2&c", std::string());
672 std::map<std::string, std::string> params; 675 std::map<std::string, std::string> params;
673 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params); 676 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params);
674 EXPECT_EQ(id, params["id"]); 677 EXPECT_EQ(id, params["id"]);
675 EXPECT_EQ(version, params["v"]); 678 EXPECT_EQ(version, params["v"]);
676 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); 679 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]);
677 } 680 }
678 681
679 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { 682 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) {
680 net::TestURLFetcherFactory factory; 683 net::TestURLFetcherFactory factory;
681 684
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 UpdateManifest::Results updates; 734 UpdateManifest::Results updates;
732 std::vector<int> updateable; 735 std::vector<int> updateable;
733 downloader.DetermineUpdates(fetch_data, updates, &updateable); 736 downloader.DetermineUpdates(fetch_data, updates, &updateable);
734 EXPECT_TRUE(updateable.empty()); 737 EXPECT_TRUE(updateable.empty());
735 738
736 // Create two updates - expect that DetermineUpdates will return the first 739 // Create two updates - expect that DetermineUpdates will return the first
737 // one (v1.0 installed, v1.1 available) but not the second one (both 740 // one (v1.0 installed, v1.1 available) but not the second one (both
738 // installed and available at v2.0). 741 // installed and available at v2.0).
739 const std::string id1 = id_util::GenerateId("1"); 742 const std::string id1 = id_util::GenerateId("1");
740 const std::string id2 = id_util::GenerateId("2"); 743 const std::string id2 = id_util::GenerateId("2");
741 fetch_data.AddExtension(id1, "1.0.0.0", 744 fetch_data.AddExtension(
742 &kNeverPingedData, kEmptyUpdateUrlData, ""); 745 id1, "1.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string());
743 AddParseResult(id1, "1.1", 746 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates);
744 "http://localhost/e1_1.1.crx", &updates); 747 fetch_data.AddExtension(
745 fetch_data.AddExtension(id2, "2.0.0.0", 748 id2, "2.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string());
746 &kNeverPingedData, kEmptyUpdateUrlData, ""); 749 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates);
747 AddParseResult(id2, "2.0.0.0",
748 "http://localhost/e2_2.0.crx", &updates);
749 750
750 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); 751 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false));
751 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _)) 752 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _))
752 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"), 753 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"),
753 Return(true))); 754 Return(true)));
754 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _)) 755 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _))
755 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), 756 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"),
756 Return(true))); 757 Return(true)));
757 758
758 downloader.DetermineUpdates(fetch_data, updates, &updateable); 759 downloader.DetermineUpdates(fetch_data, updates, &updateable);
(...skipping 16 matching lines...) Expand all
775 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 776 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
776 UpdateManifest::Results updates; 777 UpdateManifest::Results updates;
777 778
778 std::list<std::string> ids_for_update_check; 779 std::list<std::string> ids_for_update_check;
779 pending_extension_manager->GetPendingIdsForUpdateCheck( 780 pending_extension_manager->GetPendingIdsForUpdateCheck(
780 &ids_for_update_check); 781 &ids_for_update_check);
781 782
782 std::list<std::string>::const_iterator it; 783 std::list<std::string>::const_iterator it;
783 for (it = ids_for_update_check.begin(); 784 for (it = ids_for_update_check.begin();
784 it != ids_for_update_check.end(); ++it) { 785 it != ids_for_update_check.end(); ++it) {
785 fetch_data.AddExtension(*it, "1.0.0.0", 786 fetch_data.AddExtension(*it,
786 &kNeverPingedData, kEmptyUpdateUrlData, ""); 787 "1.0.0.0",
788 &kNeverPingedData,
789 kEmptyUpdateUrlData,
790 std::string());
787 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); 791 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates);
788 } 792 }
789 793
790 // The delegate will tell the downloader that all the extensions are 794 // The delegate will tell the downloader that all the extensions are
791 // pending. 795 // pending.
792 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true)); 796 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true));
793 797
794 std::vector<int> updateable; 798 std::vector<int> updateable;
795 downloader.DetermineUpdates(fetch_data, updates, &updateable); 799 downloader.DetermineUpdates(fetch_data, updates, &updateable);
796 // All the apps should be updateable. 800 // All the apps should be updateable.
(...skipping 12 matching lines...) Expand all
809 ExtensionDownloader downloader(&delegate, service.request_context()); 813 ExtensionDownloader downloader(&delegate, service.request_context());
810 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); 814 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy);
811 815
812 GURL kUpdateUrl("http://localhost/manifest1"); 816 GURL kUpdateUrl("http://localhost/manifest1");
813 817
814 scoped_ptr<ManifestFetchData> fetch1(new ManifestFetchData(kUpdateUrl, 0)); 818 scoped_ptr<ManifestFetchData> fetch1(new ManifestFetchData(kUpdateUrl, 0));
815 scoped_ptr<ManifestFetchData> fetch2(new ManifestFetchData(kUpdateUrl, 0)); 819 scoped_ptr<ManifestFetchData> fetch2(new ManifestFetchData(kUpdateUrl, 0));
816 scoped_ptr<ManifestFetchData> fetch3(new ManifestFetchData(kUpdateUrl, 0)); 820 scoped_ptr<ManifestFetchData> fetch3(new ManifestFetchData(kUpdateUrl, 0));
817 scoped_ptr<ManifestFetchData> fetch4(new ManifestFetchData(kUpdateUrl, 0)); 821 scoped_ptr<ManifestFetchData> fetch4(new ManifestFetchData(kUpdateUrl, 0));
818 ManifestFetchData::PingData zeroDays(0, 0, true); 822 ManifestFetchData::PingData zeroDays(0, 0, true);
819 fetch1->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, ""); 823 fetch1->AddExtension(
820 fetch2->AddExtension("2222", "2.0", &zeroDays, kEmptyUpdateUrlData, ""); 824 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string());
821 fetch3->AddExtension("3333", "3.0", &zeroDays, kEmptyUpdateUrlData, ""); 825 fetch2->AddExtension(
822 fetch4->AddExtension("4444", "4.0", &zeroDays, kEmptyUpdateUrlData, ""); 826 "2222", "2.0", &zeroDays, kEmptyUpdateUrlData, std::string());
827 fetch3->AddExtension(
828 "3333", "3.0", &zeroDays, kEmptyUpdateUrlData, std::string());
829 fetch4->AddExtension(
830 "4444", "4.0", &zeroDays, kEmptyUpdateUrlData, std::string());
823 831
824 // This will start the first fetcher and queue the others. The next in queue 832 // This will start the first fetcher and queue the others. The next in queue
825 // is started as each fetcher receives its response. 833 // is started as each fetcher receives its response.
826 downloader.StartUpdateCheck(fetch1.Pass()); 834 downloader.StartUpdateCheck(fetch1.Pass());
827 downloader.StartUpdateCheck(fetch2.Pass()); 835 downloader.StartUpdateCheck(fetch2.Pass());
828 downloader.StartUpdateCheck(fetch3.Pass()); 836 downloader.StartUpdateCheck(fetch3.Pass());
829 downloader.StartUpdateCheck(fetch4.Pass()); 837 downloader.StartUpdateCheck(fetch4.Pass());
830 RunUntilIdle(); 838 RunUntilIdle();
831 839
832 // The first fetch will fail. 840 // The first fetch will fail.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 NotificationsObserver observer; 928 NotificationsObserver observer;
921 MockService service(prefs_.get()); 929 MockService service(prefs_.get());
922 MockExtensionDownloaderDelegate delegate; 930 MockExtensionDownloaderDelegate delegate;
923 ExtensionDownloader downloader(&delegate, service.request_context()); 931 ExtensionDownloader downloader(&delegate, service.request_context());
924 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); 932 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy);
925 933
926 GURL kUpdateUrl("http://localhost/manifest1"); 934 GURL kUpdateUrl("http://localhost/manifest1");
927 935
928 scoped_ptr<ManifestFetchData> fetch(new ManifestFetchData(kUpdateUrl, 0)); 936 scoped_ptr<ManifestFetchData> fetch(new ManifestFetchData(kUpdateUrl, 0));
929 ManifestFetchData::PingData zeroDays(0, 0, true); 937 ManifestFetchData::PingData zeroDays(0, 0, true);
930 fetch->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, ""); 938 fetch->AddExtension(
939 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string());
931 940
932 // This will start the first fetcher. 941 // This will start the first fetcher.
933 downloader.StartUpdateCheck(fetch.Pass()); 942 downloader.StartUpdateCheck(fetch.Pass());
934 RunUntilIdle(); 943 RunUntilIdle();
935 944
936 // ExtensionDownloader should retry kMaxRetries times and then fail. 945 // ExtensionDownloader should retry kMaxRetries times and then fail.
937 EXPECT_CALL(delegate, OnExtensionDownloadFailed( 946 EXPECT_CALL(delegate, OnExtensionDownloadFailed(
938 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); 947 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _));
939 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) { 948 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) {
940 // All fetches will fail. 949 // All fetches will fail.
941 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 950 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
942 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 951 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
943 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); 952 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags);
944 fetcher->set_url(kUpdateUrl); 953 fetcher->set_url(kUpdateUrl);
945 fetcher->set_status(net::URLRequestStatus()); 954 fetcher->set_status(net::URLRequestStatus());
946 // Code 5xx causes ExtensionDownloader to retry. 955 // Code 5xx causes ExtensionDownloader to retry.
947 fetcher->set_response_code(500); 956 fetcher->set_response_code(500);
948 fetcher->delegate()->OnURLFetchComplete(fetcher); 957 fetcher->delegate()->OnURLFetchComplete(fetcher);
949 RunUntilIdle(); 958 RunUntilIdle();
950 } 959 }
951 Mock::VerifyAndClearExpectations(&delegate); 960 Mock::VerifyAndClearExpectations(&delegate);
952 961
953 962
954 // For response codes that are not in the 5xx range ExtensionDownloader 963 // For response codes that are not in the 5xx range ExtensionDownloader
955 // should not retry. 964 // should not retry.
956 fetch.reset(new ManifestFetchData(kUpdateUrl, 0)); 965 fetch.reset(new ManifestFetchData(kUpdateUrl, 0));
957 fetch->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, ""); 966 fetch->AddExtension(
967 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string());
958 968
959 // This will start the first fetcher. 969 // This will start the first fetcher.
960 downloader.StartUpdateCheck(fetch.Pass()); 970 downloader.StartUpdateCheck(fetch.Pass());
961 RunUntilIdle(); 971 RunUntilIdle();
962 972
963 EXPECT_CALL(delegate, OnExtensionDownloadFailed( 973 EXPECT_CALL(delegate, OnExtensionDownloadFailed(
964 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); 974 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _));
965 // The first fetch will fail, and require retrying. 975 // The first fetch will fail, and require retrying.
966 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 976 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
967 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 977 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 updater.Start(); 1009 updater.Start();
1000 ResetDownloader( 1010 ResetDownloader(
1001 &updater, 1011 &updater,
1002 new ExtensionDownloader(&updater, service->request_context())); 1012 new ExtensionDownloader(&updater, service->request_context()));
1003 updater.downloader_->extensions_queue_.set_backoff_policy( 1013 updater.downloader_->extensions_queue_.set_backoff_policy(
1004 &kNoBackoffPolicy); 1014 &kNoBackoffPolicy);
1005 1015
1006 GURL test_url("http://localhost/extension.crx"); 1016 GURL test_url("http://localhost/extension.crx");
1007 1017
1008 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 1018 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1009 std::string hash = ""; 1019 std::string hash;
1010 Version version("0.0.1"); 1020 Version version("0.0.1");
1011 std::set<int> requests; 1021 std::set<int> requests;
1012 requests.insert(0); 1022 requests.insert(0);
1013 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch( 1023 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch(
1014 new ExtensionDownloader::ExtensionFetch( 1024 new ExtensionDownloader::ExtensionFetch(
1015 id, test_url, hash, version.GetString(), requests)); 1025 id, test_url, hash, version.GetString(), requests));
1016 updater.downloader_->FetchUpdatedExtension(fetch.Pass()); 1026 updater.downloader_->FetchUpdatedExtension(fetch.Pass());
1017 1027
1018 if (pending) { 1028 if (pending) {
1019 const bool kIsFromSync = true; 1029 const bool kIsFromSync = true;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 &kNoBackoffPolicy); 1145 &kNoBackoffPolicy);
1136 1146
1137 EXPECT_FALSE(updater.crx_install_is_running_); 1147 EXPECT_FALSE(updater.crx_install_is_running_);
1138 1148
1139 GURL url1("http://localhost/extension1.crx"); 1149 GURL url1("http://localhost/extension1.crx");
1140 GURL url2("http://localhost/extension2.crx"); 1150 GURL url2("http://localhost/extension2.crx");
1141 1151
1142 std::string id1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 1152 std::string id1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1143 std::string id2 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; 1153 std::string id2 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
1144 1154
1145 std::string hash1 = ""; 1155 std::string hash1;
1146 std::string hash2 = ""; 1156 std::string hash2;
1147 1157
1148 std::string version1 = "0.1"; 1158 std::string version1 = "0.1";
1149 std::string version2 = "0.1"; 1159 std::string version2 = "0.1";
1150 std::set<int> requests; 1160 std::set<int> requests;
1151 requests.insert(0); 1161 requests.insert(0);
1152 // Start two fetches 1162 // Start two fetches
1153 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch1( 1163 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch1(
1154 new ExtensionDownloader::ExtensionFetch( 1164 new ExtensionDownloader::ExtensionFetch(
1155 id1, url1, hash1, version1, requests)); 1165 id1, url1, hash1, version1, requests));
1156 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch2( 1166 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch2(
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 // fetch. 1360 // fetch.
1351 std::vector<GURL> fetched_urls; 1361 std::vector<GURL> fetched_urls;
1352 net::TestURLFetcher* fetcher = 1362 net::TestURLFetcher* fetcher =
1353 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 1363 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
1354 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 1364 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
1355 fetched_urls.push_back(fetcher->GetOriginalURL()); 1365 fetched_urls.push_back(fetcher->GetOriginalURL());
1356 1366
1357 fetcher->set_url(fetched_urls[0]); 1367 fetcher->set_url(fetched_urls[0]);
1358 fetcher->set_status(net::URLRequestStatus()); 1368 fetcher->set_status(net::URLRequestStatus());
1359 fetcher->set_response_code(500); 1369 fetcher->set_response_code(500);
1360 fetcher->SetResponseString(""); 1370 fetcher->SetResponseString(std::string());
1361 fetcher->delegate()->OnURLFetchComplete(fetcher); 1371 fetcher->delegate()->OnURLFetchComplete(fetcher);
1362 1372
1363 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 1373 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
1364 fetched_urls.push_back(fetcher->GetOriginalURL()); 1374 fetched_urls.push_back(fetcher->GetOriginalURL());
1365 1375
1366 // The urls could have been fetched in either order, so use the host to 1376 // The urls could have been fetched in either order, so use the host to
1367 // tell them apart and note the query each used. 1377 // tell them apart and note the query each used.
1368 std::string url1_query; 1378 std::string url1_query;
1369 std::string url2_query; 1379 std::string url2_query;
1370 if (fetched_urls[0].host() == url1.host()) { 1380 if (fetched_urls[0].host() == url1.host()) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 ExtensionUpdater updater( 1445 ExtensionUpdater updater(
1436 &service, service.extension_prefs(), service.pref_service(), 1446 &service, service.extension_prefs(), service.pref_service(),
1437 service.profile(), service.blacklist(), kUpdateFrequencySecs); 1447 service.profile(), service.blacklist(), kUpdateFrequencySecs);
1438 updater.Start(); 1448 updater.Start();
1439 ResetDownloader( 1449 ResetDownloader(
1440 &updater, 1450 &updater,
1441 new ExtensionDownloader(&updater, service.request_context())); 1451 new ExtensionDownloader(&updater, service.request_context()));
1442 1452
1443 ManifestFetchData fetch_data(update_url, 0); 1453 ManifestFetchData fetch_data(update_url, 0);
1444 const Extension* extension = tmp[0]; 1454 const Extension* extension = tmp[0];
1445 fetch_data.AddExtension(extension->id(), extension->VersionString(), 1455 fetch_data.AddExtension(extension->id(),
1446 &kNeverPingedData, kEmptyUpdateUrlData, ""); 1456 extension->VersionString(),
1457 &kNeverPingedData,
1458 kEmptyUpdateUrlData,
1459 std::string());
1447 UpdateManifest::Results results; 1460 UpdateManifest::Results results;
1448 results.daystart_elapsed_seconds = 750; 1461 results.daystart_elapsed_seconds = 750;
1449 1462
1450 updater.downloader_->HandleManifestResults(fetch_data, &results); 1463 updater.downloader_->HandleManifestResults(fetch_data, &results);
1451 Time last_ping_day = 1464 Time last_ping_day =
1452 service.extension_prefs()->LastPingDay(extension->id()); 1465 service.extension_prefs()->LastPingDay(extension->id());
1453 EXPECT_FALSE(last_ping_day.is_null()); 1466 EXPECT_FALSE(last_ping_day.is_null());
1454 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds(); 1467 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds();
1455 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); 1468 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5);
1456 } 1469 }
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); 1653 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get()));
1641 1654
1642 // Extensions with invalid update URLs should be rejected. 1655 // Extensions with invalid update URLs should be rejected.
1643 id = id_util::GenerateId("foo2"); 1656 id = id_util::GenerateId("foo2");
1644 EXPECT_FALSE( 1657 EXPECT_FALSE(
1645 downloader->AddPendingExtension(id, GURL("http:google.com:foo"), 0)); 1658 downloader->AddPendingExtension(id, GURL("http:google.com:foo"), 0));
1646 downloader->StartAllPending(); 1659 downloader->StartAllPending();
1647 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); 1660 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get()));
1648 1661
1649 // Extensions with empty IDs should be rejected. 1662 // Extensions with empty IDs should be rejected.
1650 EXPECT_FALSE(downloader->AddPendingExtension("", GURL(), 0)); 1663 EXPECT_FALSE(downloader->AddPendingExtension(std::string(), GURL(), 0));
1651 downloader->StartAllPending(); 1664 downloader->StartAllPending();
1652 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); 1665 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get()));
1653 1666
1654 // TODO(akalin): Test that extensions with empty update URLs 1667 // TODO(akalin): Test that extensions with empty update URLs
1655 // converted from user scripts are rejected. 1668 // converted from user scripts are rejected.
1656 1669
1657 // Reset the ExtensionDownloader so that it drops the current fetcher. 1670 // Reset the ExtensionDownloader so that it drops the current fetcher.
1658 downloader.reset( 1671 downloader.reset(
1659 new ExtensionDownloader(&delegate, service.request_context())); 1672 new ExtensionDownloader(&delegate, service.request_context()));
1660 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); 1673 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get()));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 // -prodversionmin (shouldn't update if browser version too old) 1726 // -prodversionmin (shouldn't update if browser version too old)
1714 // -manifests & updates arriving out of order / interleaved 1727 // -manifests & updates arriving out of order / interleaved
1715 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 1728 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
1716 // -An extension gets uninstalled while updates are in progress (so it doesn't 1729 // -An extension gets uninstalled while updates are in progress (so it doesn't
1717 // "come back from the dead") 1730 // "come back from the dead")
1718 // -An extension gets manually updated to v3 while we're downloading v2 (ie 1731 // -An extension gets manually updated to v3 while we're downloading v2 (ie
1719 // you don't get downgraded accidentally) 1732 // you don't get downgraded accidentally)
1720 // -An update manifest mentions multiple updates 1733 // -An update manifest mentions multiple updates
1721 1734
1722 } // namespace extensions 1735 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/extension_updater.cc ('k') | chrome/browser/extensions/webstore_installer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698