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

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

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/updater/extension_updater.h" 5 #include "chrome/browser/extensions/updater/extension_updater.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9
9 #include <list> 10 #include <list>
10 #include <map> 11 #include <map>
12 #include <memory>
11 #include <set> 13 #include <set>
12 #include <utility> 14 #include <utility>
13 #include <vector> 15 #include <vector>
14 16
15 #include "base/bind.h" 17 #include "base/bind.h"
16 #include "base/bind_helpers.h" 18 #include "base/bind_helpers.h"
17 #include "base/command_line.h" 19 #include "base/command_line.h"
18 #include "base/compiler_specific.h" 20 #include "base/compiler_specific.h"
19 #include "base/macros.h" 21 #include "base/macros.h"
20 #include "base/memory/scoped_ptr.h"
21 #include "base/memory/weak_ptr.h" 22 #include "base/memory/weak_ptr.h"
22 #include "base/message_loop/message_loop.h" 23 #include "base/message_loop/message_loop.h"
23 #include "base/run_loop.h" 24 #include "base/run_loop.h"
24 #include "base/sequenced_task_runner.h" 25 #include "base/sequenced_task_runner.h"
25 #include "base/stl_util.h" 26 #include "base/stl_util.h"
26 #include "base/strings/string_number_conversions.h" 27 #include "base/strings/string_number_conversions.h"
27 #include "base/strings/string_split.h" 28 #include "base/strings/string_split.h"
28 #include "base/strings/string_util.h" 29 #include "base/strings/string_util.h"
29 #include "base/strings/stringprintf.h" 30 #include "base/strings/stringprintf.h"
30 #include "base/thread_task_runner_handle.h" 31 #include "base/thread_task_runner_handle.h"
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 void OverrideDownloaderDelegate(ExtensionDownloaderDelegate* delegate) { 367 void OverrideDownloaderDelegate(ExtensionDownloaderDelegate* delegate) {
367 downloader_delegate_override_ = delegate; 368 downloader_delegate_override_ = delegate;
368 } 369 }
369 370
370 protected: 371 protected:
371 TestExtensionPrefs* const prefs_; 372 TestExtensionPrefs* const prefs_;
372 TestingProfile profile_; 373 TestingProfile profile_;
373 PendingExtensionManager pending_extension_manager_; 374 PendingExtensionManager pending_extension_manager_;
374 375
375 private: 376 private:
376 scoped_ptr<ExtensionDownloader> CreateExtensionDownloader( 377 std::unique_ptr<ExtensionDownloader> CreateExtensionDownloader(
377 ExtensionDownloaderDelegate* delegate) { 378 ExtensionDownloaderDelegate* delegate) {
378 scoped_ptr<ExtensionDownloader> downloader = 379 std::unique_ptr<ExtensionDownloader> downloader =
379 ChromeExtensionDownloaderFactory::CreateForRequestContext( 380 ChromeExtensionDownloaderFactory::CreateForRequestContext(
380 request_context(), 381 request_context(), downloader_delegate_override_
381 downloader_delegate_override_ ? downloader_delegate_override_ 382 ? downloader_delegate_override_
382 : delegate); 383 : delegate);
383 if (enable_metrics_) 384 if (enable_metrics_)
384 downloader->set_enable_extra_update_metrics(true); 385 downloader->set_enable_extra_update_metrics(true);
385 return downloader; 386 return downloader;
386 } 387 }
387 388
388 scoped_ptr<ExtensionDownloader> CreateExtensionDownloaderWithIdentity( 389 std::unique_ptr<ExtensionDownloader> CreateExtensionDownloaderWithIdentity(
389 ExtensionDownloaderDelegate* delegate) { 390 ExtensionDownloaderDelegate* delegate) {
390 scoped_ptr<FakeIdentityProvider> fake_identity_provider; 391 std::unique_ptr<FakeIdentityProvider> fake_identity_provider;
391 fake_token_service_.reset(new FakeOAuth2TokenService()); 392 fake_token_service_.reset(new FakeOAuth2TokenService());
392 fake_identity_provider.reset(new FakeIdentityProvider( 393 fake_identity_provider.reset(new FakeIdentityProvider(
393 fake_token_service_.get())); 394 fake_token_service_.get()));
394 fake_identity_provider->LogIn(kFakeAccountId); 395 fake_identity_provider->LogIn(kFakeAccountId);
395 fake_token_service_->AddAccount(kFakeAccountId); 396 fake_token_service_->AddAccount(kFakeAccountId);
396 397
397 scoped_ptr<ExtensionDownloader> downloader( 398 std::unique_ptr<ExtensionDownloader> downloader(
398 CreateExtensionDownloader(delegate)); 399 CreateExtensionDownloader(delegate));
399 downloader->SetWebstoreIdentityProvider(std::move(fake_identity_provider)); 400 downloader->SetWebstoreIdentityProvider(std::move(fake_identity_provider));
400 return downloader; 401 return downloader;
401 } 402 }
402 403
403 scoped_ptr<FakeOAuth2TokenService> fake_token_service_; 404 std::unique_ptr<FakeOAuth2TokenService> fake_token_service_;
404 405
405 ExtensionDownloaderDelegate* downloader_delegate_override_; 406 ExtensionDownloaderDelegate* downloader_delegate_override_;
406 407
407 bool enable_metrics_; 408 bool enable_metrics_;
408 409
409 DISALLOW_COPY_AND_ASSIGN(MockService); 410 DISALLOW_COPY_AND_ASSIGN(MockService);
410 }; 411 };
411 412
412 413
413 bool ShouldInstallExtensionsOnly(const Extension* extension) { 414 bool ShouldInstallExtensionsOnly(const Extension* extension) {
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 UpdateManifest::Results* results) { 688 UpdateManifest::Results* results) {
688 UpdateManifest::Result result; 689 UpdateManifest::Result result;
689 result.extension_id = id; 690 result.extension_id = id;
690 result.version = version; 691 result.version = version;
691 result.crx_url = GURL(url); 692 result.crx_url = GURL(url);
692 results->list.push_back(result); 693 results->list.push_back(result);
693 } 694 }
694 695
695 void StartUpdateCheck(ExtensionDownloader* downloader, 696 void StartUpdateCheck(ExtensionDownloader* downloader,
696 ManifestFetchData* fetch_data) { 697 ManifestFetchData* fetch_data) {
697 downloader->StartUpdateCheck(scoped_ptr<ManifestFetchData>(fetch_data)); 698 downloader->StartUpdateCheck(
699 std::unique_ptr<ManifestFetchData>(fetch_data));
698 } 700 }
699 701
700 size_t ManifestFetchersCount(ExtensionDownloader* downloader) { 702 size_t ManifestFetchersCount(ExtensionDownloader* downloader) {
701 return downloader->manifests_queue_.size() + 703 return downloader->manifests_queue_.size() +
702 (downloader->manifest_fetcher_.get() ? 1 : 0); 704 (downloader->manifest_fetcher_.get() ? 1 : 0);
703 } 705 }
704 706
705 void TestExtensionUpdateCheckRequests(bool pending) { 707 void TestExtensionUpdateCheckRequests(bool pending) {
706 // Create an extension with an update_url. 708 // Create an extension with an update_url.
707 ServiceForManifestTests service(prefs_.get()); 709 ServiceForManifestTests service(prefs_.get());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 } 761 }
760 EXPECT_EQ("", params["uc"]); 762 EXPECT_EQ("", params["uc"]);
761 } 763 }
762 764
763 void TestUpdateUrlDataEmpty() { 765 void TestUpdateUrlDataEmpty() {
764 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 766 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
765 const std::string version = "1.0"; 767 const std::string version = "1.0";
766 768
767 // Make sure that an empty update URL data string does not cause a ap= 769 // Make sure that an empty update URL data string does not cause a ap=
768 // option to appear in the x= parameter. 770 // option to appear in the x= parameter.
769 scoped_ptr<ManifestFetchData> fetch_data( 771 std::unique_ptr<ManifestFetchData> fetch_data(
770 CreateManifestFetchData(GURL("http://localhost/foo"))); 772 CreateManifestFetchData(GURL("http://localhost/foo")));
771 fetch_data->AddExtension(id, version, &kNeverPingedData, std::string(), 773 fetch_data->AddExtension(id, version, &kNeverPingedData, std::string(),
772 std::string()); 774 std::string());
773 775
774 std::map<std::string, std::string> params; 776 std::map<std::string, std::string> params;
775 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params); 777 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params);
776 EXPECT_EQ(id, params["id"]); 778 EXPECT_EQ(id, params["id"]);
777 EXPECT_EQ(version, params["v"]); 779 EXPECT_EQ(version, params["v"]);
778 EXPECT_EQ(0U, params.count("ap")); 780 EXPECT_EQ(0U, params.count("ap"));
779 } 781 }
780 782
781 void TestUpdateUrlDataSimple() { 783 void TestUpdateUrlDataSimple() {
782 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 784 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
783 const std::string version = "1.0"; 785 const std::string version = "1.0";
784 786
785 // Make sure that an update URL data string causes an appropriate ap= 787 // Make sure that an update URL data string causes an appropriate ap=
786 // option to appear in the x= parameter. 788 // option to appear in the x= parameter.
787 scoped_ptr<ManifestFetchData> fetch_data( 789 std::unique_ptr<ManifestFetchData> fetch_data(
788 CreateManifestFetchData(GURL("http://localhost/foo"))); 790 CreateManifestFetchData(GURL("http://localhost/foo")));
789 fetch_data->AddExtension(id, version, &kNeverPingedData, "bar", 791 fetch_data->AddExtension(id, version, &kNeverPingedData, "bar",
790 std::string()); 792 std::string());
791 std::map<std::string, std::string> params; 793 std::map<std::string, std::string> params;
792 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params); 794 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params);
793 EXPECT_EQ(id, params["id"]); 795 EXPECT_EQ(id, params["id"]);
794 EXPECT_EQ(version, params["v"]); 796 EXPECT_EQ(version, params["v"]);
795 EXPECT_EQ("bar", params["ap"]); 797 EXPECT_EQ("bar", params["ap"]);
796 } 798 }
797 799
798 void TestUpdateUrlDataCompound() { 800 void TestUpdateUrlDataCompound() {
799 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 801 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
800 const std::string version = "1.0"; 802 const std::string version = "1.0";
801 803
802 // Make sure that an update URL data string causes an appropriate ap= 804 // Make sure that an update URL data string causes an appropriate ap=
803 // option to appear in the x= parameter. 805 // option to appear in the x= parameter.
804 scoped_ptr<ManifestFetchData> fetch_data( 806 std::unique_ptr<ManifestFetchData> fetch_data(
805 CreateManifestFetchData(GURL("http://localhost/foo"))); 807 CreateManifestFetchData(GURL("http://localhost/foo")));
806 fetch_data->AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c", 808 fetch_data->AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c",
807 std::string()); 809 std::string());
808 std::map<std::string, std::string> params; 810 std::map<std::string, std::string> params;
809 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params); 811 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params);
810 EXPECT_EQ(id, params["id"]); 812 EXPECT_EQ(id, params["id"]);
811 EXPECT_EQ(version, params["v"]); 813 EXPECT_EQ(version, params["v"]);
812 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); 814 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]);
813 } 815 }
814 816
(...skipping 24 matching lines...) Expand all
839 std::string::size_type ap = update_url.find("ap%3D", x); 841 std::string::size_type ap = update_url.find("ap%3D", x);
840 EXPECT_EQ(std::string::npos, ap); 842 EXPECT_EQ(std::string::npos, ap);
841 } 843 }
842 844
843 void TestInstallSource() { 845 void TestInstallSource() {
844 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 846 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
845 const std::string version = "1.0"; 847 const std::string version = "1.0";
846 const std::string install_source = "instally"; 848 const std::string install_source = "instally";
847 849
848 // Make sure that an installsource= appears in the x= parameter. 850 // Make sure that an installsource= appears in the x= parameter.
849 scoped_ptr<ManifestFetchData> fetch_data( 851 std::unique_ptr<ManifestFetchData> fetch_data(
850 CreateManifestFetchData(GURL("http://localhost/foo"))); 852 CreateManifestFetchData(GURL("http://localhost/foo")));
851 fetch_data->AddExtension(id, version, &kNeverPingedData, 853 fetch_data->AddExtension(id, version, &kNeverPingedData,
852 kEmptyUpdateUrlData, install_source); 854 kEmptyUpdateUrlData, install_source);
853 std::map<std::string, std::string> params; 855 std::map<std::string, std::string> params;
854 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params); 856 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params);
855 EXPECT_EQ(id, params["id"]); 857 EXPECT_EQ(id, params["id"]);
856 EXPECT_EQ(version, params["v"]); 858 EXPECT_EQ(version, params["v"]);
857 EXPECT_EQ(install_source, params["installsource"]); 859 EXPECT_EQ(install_source, params["installsource"]);
858 } 860 }
859 861
860 void TestDetermineUpdates() { 862 void TestDetermineUpdates() {
861 TestingProfile profile; 863 TestingProfile profile;
862 MockExtensionDownloaderDelegate delegate; 864 MockExtensionDownloaderDelegate delegate;
863 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); 865 ExtensionDownloader downloader(&delegate, profile.GetRequestContext());
864 866
865 // Check passing an empty list of parse results to DetermineUpdates 867 // Check passing an empty list of parse results to DetermineUpdates
866 scoped_ptr<ManifestFetchData> fetch_data( 868 std::unique_ptr<ManifestFetchData> fetch_data(
867 CreateManifestFetchData(GURL("http://localhost/foo"))); 869 CreateManifestFetchData(GURL("http://localhost/foo")));
868 UpdateManifest::Results updates; 870 UpdateManifest::Results updates;
869 std::vector<int> updateable; 871 std::vector<int> updateable;
870 downloader.DetermineUpdates(*fetch_data, updates, &updateable); 872 downloader.DetermineUpdates(*fetch_data, updates, &updateable);
871 EXPECT_TRUE(updateable.empty()); 873 EXPECT_TRUE(updateable.empty());
872 874
873 // Create two updates - expect that DetermineUpdates will return the first 875 // Create two updates - expect that DetermineUpdates will return the first
874 // one (v1.0 installed, v1.1 available) but not the second one (both 876 // one (v1.0 installed, v1.1 available) but not the second one (both
875 // installed and available at v2.0). 877 // installed and available at v2.0).
876 const std::string id1 = crx_file::id_util::GenerateId("1"); 878 const std::string id1 = crx_file::id_util::GenerateId("1");
(...skipping 22 matching lines...) Expand all
899 // Create a set of test extensions 901 // Create a set of test extensions
900 ServiceForManifestTests service(prefs_.get()); 902 ServiceForManifestTests service(prefs_.get());
901 PendingExtensionManager* pending_extension_manager = 903 PendingExtensionManager* pending_extension_manager =
902 service.pending_extension_manager(); 904 service.pending_extension_manager();
903 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); 905 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager);
904 906
905 TestingProfile profile; 907 TestingProfile profile;
906 MockExtensionDownloaderDelegate delegate; 908 MockExtensionDownloaderDelegate delegate;
907 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); 909 ExtensionDownloader downloader(&delegate, profile.GetRequestContext());
908 910
909 scoped_ptr<ManifestFetchData> fetch_data( 911 std::unique_ptr<ManifestFetchData> fetch_data(
910 CreateManifestFetchData(GURL("http://localhost/foo"))); 912 CreateManifestFetchData(GURL("http://localhost/foo")));
911 UpdateManifest::Results updates; 913 UpdateManifest::Results updates;
912 914
913 std::list<std::string> ids_for_update_check; 915 std::list<std::string> ids_for_update_check;
914 pending_extension_manager->GetPendingIdsForUpdateCheck( 916 pending_extension_manager->GetPendingIdsForUpdateCheck(
915 &ids_for_update_check); 917 &ids_for_update_check);
916 918
917 std::list<std::string>::const_iterator it; 919 std::list<std::string>::const_iterator it;
918 for (it = ids_for_update_check.begin(); 920 for (it = ids_for_update_check.begin();
919 it != ids_for_update_check.end(); ++it) { 921 it != ids_for_update_check.end(); ++it) {
(...skipping 19 matching lines...) Expand all
939 net::TestURLFetcherFactory factory; 941 net::TestURLFetcherFactory factory;
940 factory.set_remove_fetcher_on_delete(true); 942 factory.set_remove_fetcher_on_delete(true);
941 net::TestURLFetcher* fetcher = NULL; 943 net::TestURLFetcher* fetcher = NULL;
942 MockService service(prefs_.get()); 944 MockService service(prefs_.get());
943 MockExtensionDownloaderDelegate delegate; 945 MockExtensionDownloaderDelegate delegate;
944 ExtensionDownloader downloader(&delegate, service.request_context()); 946 ExtensionDownloader downloader(&delegate, service.request_context());
945 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); 947 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy);
946 948
947 GURL kUpdateUrl("http://localhost/manifest1"); 949 GURL kUpdateUrl("http://localhost/manifest1");
948 950
949 scoped_ptr<ManifestFetchData> fetch1(CreateManifestFetchData(kUpdateUrl)); 951 std::unique_ptr<ManifestFetchData> fetch1(
950 scoped_ptr<ManifestFetchData> fetch2(CreateManifestFetchData(kUpdateUrl)); 952 CreateManifestFetchData(kUpdateUrl));
951 scoped_ptr<ManifestFetchData> fetch3(CreateManifestFetchData(kUpdateUrl)); 953 std::unique_ptr<ManifestFetchData> fetch2(
952 scoped_ptr<ManifestFetchData> fetch4(CreateManifestFetchData(kUpdateUrl)); 954 CreateManifestFetchData(kUpdateUrl));
955 std::unique_ptr<ManifestFetchData> fetch3(
956 CreateManifestFetchData(kUpdateUrl));
957 std::unique_ptr<ManifestFetchData> fetch4(
958 CreateManifestFetchData(kUpdateUrl));
953 ManifestFetchData::PingData zeroDays(0, 0, true, 0); 959 ManifestFetchData::PingData zeroDays(0, 0, true, 0);
954 fetch1->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, 960 fetch1->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData,
955 std::string()); 961 std::string());
956 fetch2->AddExtension("2222", "2.0", &zeroDays, kEmptyUpdateUrlData, 962 fetch2->AddExtension("2222", "2.0", &zeroDays, kEmptyUpdateUrlData,
957 std::string()); 963 std::string());
958 fetch3->AddExtension("3333", "3.0", &zeroDays, kEmptyUpdateUrlData, 964 fetch3->AddExtension("3333", "3.0", &zeroDays, kEmptyUpdateUrlData,
959 std::string()); 965 std::string());
960 fetch4->AddExtension("4444", "4.0", &zeroDays, kEmptyUpdateUrlData, 966 fetch4->AddExtension("4444", "4.0", &zeroDays, kEmptyUpdateUrlData,
961 std::string()); 967 std::string());
962 968
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 net::TestURLFetcherFactory factory; 1085 net::TestURLFetcherFactory factory;
1080 net::TestURLFetcher* fetcher = NULL; 1086 net::TestURLFetcher* fetcher = NULL;
1081 NotificationsObserver observer; 1087 NotificationsObserver observer;
1082 MockService service(prefs_.get()); 1088 MockService service(prefs_.get());
1083 MockExtensionDownloaderDelegate delegate; 1089 MockExtensionDownloaderDelegate delegate;
1084 ExtensionDownloader downloader(&delegate, service.request_context()); 1090 ExtensionDownloader downloader(&delegate, service.request_context());
1085 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); 1091 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy);
1086 1092
1087 GURL kUpdateUrl("http://localhost/manifest1"); 1093 GURL kUpdateUrl("http://localhost/manifest1");
1088 1094
1089 scoped_ptr<ManifestFetchData> fetch(CreateManifestFetchData(kUpdateUrl)); 1095 std::unique_ptr<ManifestFetchData> fetch(
1096 CreateManifestFetchData(kUpdateUrl));
1090 ManifestFetchData::PingData zeroDays(0, 0, true, 0); 1097 ManifestFetchData::PingData zeroDays(0, 0, true, 0);
1091 fetch->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData, 1098 fetch->AddExtension("1111", "1.0", &zeroDays, kEmptyUpdateUrlData,
1092 std::string()); 1099 std::string());
1093 1100
1094 // This will start the first fetcher. 1101 // This will start the first fetcher.
1095 downloader.StartUpdateCheck(std::move(fetch)); 1102 downloader.StartUpdateCheck(std::move(fetch));
1096 RunUntilIdle(); 1103 RunUntilIdle();
1097 1104
1098 // ExtensionDownloader should retry kMaxRetries times and then fail. 1105 // ExtensionDownloader should retry kMaxRetries times and then fail.
1099 EXPECT_CALL(delegate, OnExtensionDownloadFailed( 1106 EXPECT_CALL(delegate, OnExtensionDownloadFailed(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 fetcher->set_response_code(400); 1152 fetcher->set_response_code(400);
1146 fetcher->delegate()->OnURLFetchComplete(fetcher); 1153 fetcher->delegate()->OnURLFetchComplete(fetcher);
1147 RunUntilIdle(); 1154 RunUntilIdle();
1148 1155
1149 Mock::VerifyAndClearExpectations(&delegate); 1156 Mock::VerifyAndClearExpectations(&delegate);
1150 } 1157 }
1151 1158
1152 void TestSingleExtensionDownloading(bool pending, bool retry, bool fail) { 1159 void TestSingleExtensionDownloading(bool pending, bool retry, bool fail) {
1153 net::TestURLFetcherFactory factory; 1160 net::TestURLFetcherFactory factory;
1154 net::TestURLFetcher* fetcher = NULL; 1161 net::TestURLFetcher* fetcher = NULL;
1155 scoped_ptr<ServiceForDownloadTests> service( 1162 std::unique_ptr<ServiceForDownloadTests> service(
1156 new ServiceForDownloadTests(prefs_.get())); 1163 new ServiceForDownloadTests(prefs_.get()));
1157 ExtensionUpdater updater(service.get(), 1164 ExtensionUpdater updater(service.get(),
1158 service->extension_prefs(), 1165 service->extension_prefs(),
1159 service->pref_service(), 1166 service->pref_service(),
1160 service->profile(), 1167 service->profile(),
1161 kUpdateFrequencySecs, 1168 kUpdateFrequencySecs,
1162 NULL, 1169 NULL,
1163 service->GetDownloaderFactory()); 1170 service->GetDownloaderFactory());
1164 MockExtensionDownloaderDelegate delegate; 1171 MockExtensionDownloaderDelegate delegate;
1165 delegate.DelegateTo(&updater); 1172 delegate.DelegateTo(&updater);
1166 service->OverrideDownloaderDelegate(&delegate); 1173 service->OverrideDownloaderDelegate(&delegate);
1167 updater.Start(); 1174 updater.Start();
1168 updater.EnsureDownloaderCreated(); 1175 updater.EnsureDownloaderCreated();
1169 updater.downloader_->extensions_queue_.set_backoff_policy( 1176 updater.downloader_->extensions_queue_.set_backoff_policy(
1170 &kNoBackoffPolicy); 1177 &kNoBackoffPolicy);
1171 1178
1172 GURL test_url("http://localhost/extension.crx"); 1179 GURL test_url("http://localhost/extension.crx");
1173 1180
1174 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 1181 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1175 std::string hash; 1182 std::string hash;
1176 Version version("0.0.1"); 1183 Version version("0.0.1");
1177 std::set<int> requests; 1184 std::set<int> requests;
1178 requests.insert(0); 1185 requests.insert(0);
1179 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch( 1186 std::unique_ptr<ExtensionDownloader::ExtensionFetch> fetch(
1180 new ExtensionDownloader::ExtensionFetch( 1187 new ExtensionDownloader::ExtensionFetch(id, test_url, hash,
1181 id, test_url, hash, version.GetString(), requests)); 1188 version.GetString(), requests));
1182 updater.downloader_->FetchUpdatedExtension(std::move(fetch)); 1189 updater.downloader_->FetchUpdatedExtension(std::move(fetch));
1183 1190
1184 if (pending) { 1191 if (pending) {
1185 const bool kIsFromSync = true; 1192 const bool kIsFromSync = true;
1186 const bool kMarkAcknowledged = false; 1193 const bool kMarkAcknowledged = false;
1187 const bool kRemoteInstall = false; 1194 const bool kRemoteInstall = false;
1188 PendingExtensionManager* pending_extension_manager = 1195 PendingExtensionManager* pending_extension_manager =
1189 service->pending_extension_manager(); 1196 service->pending_extension_manager();
1190 pending_extension_manager->AddForTesting( 1197 pending_extension_manager->AddForTesting(
1191 PendingExtensionInfo(id, 1198 PendingExtensionInfo(id,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 // with an OAuth2 bearer token; otherwise, or if OAuth2 failure is simulated, 1262 // with an OAuth2 bearer token; otherwise, or if OAuth2 failure is simulated,
1256 // this expects the downloader to fall back onto cookie-based credentials. 1263 // this expects the downloader to fall back onto cookie-based credentials.
1257 void TestProtectedDownload( 1264 void TestProtectedDownload(
1258 const std::string& url_prefix, 1265 const std::string& url_prefix,
1259 bool enable_oauth2, 1266 bool enable_oauth2,
1260 bool succeed_with_oauth2, 1267 bool succeed_with_oauth2,
1261 int valid_authuser, 1268 int valid_authuser,
1262 int max_authuser) { 1269 int max_authuser) {
1263 net::TestURLFetcherFactory factory; 1270 net::TestURLFetcherFactory factory;
1264 net::TestURLFetcher* fetcher = NULL; 1271 net::TestURLFetcher* fetcher = NULL;
1265 scoped_ptr<ServiceForDownloadTests> service( 1272 std::unique_ptr<ServiceForDownloadTests> service(
1266 new ServiceForDownloadTests(prefs_.get())); 1273 new ServiceForDownloadTests(prefs_.get()));
1267 const ExtensionDownloader::Factory& downloader_factory = 1274 const ExtensionDownloader::Factory& downloader_factory =
1268 enable_oauth2 ? service->GetAuthenticatedDownloaderFactory() 1275 enable_oauth2 ? service->GetAuthenticatedDownloaderFactory()
1269 : service->GetDownloaderFactory(); 1276 : service->GetDownloaderFactory();
1270 ExtensionUpdater updater( 1277 ExtensionUpdater updater(
1271 service.get(), 1278 service.get(),
1272 service->extension_prefs(), 1279 service->extension_prefs(),
1273 service->pref_service(), 1280 service->pref_service(),
1274 service->profile(), 1281 service->profile(),
1275 kUpdateFrequencySecs, 1282 kUpdateFrequencySecs,
1276 NULL, 1283 NULL,
1277 downloader_factory); 1284 downloader_factory);
1278 updater.Start(); 1285 updater.Start();
1279 updater.EnsureDownloaderCreated(); 1286 updater.EnsureDownloaderCreated();
1280 updater.downloader_->extensions_queue_.set_backoff_policy( 1287 updater.downloader_->extensions_queue_.set_backoff_policy(
1281 &kNoBackoffPolicy); 1288 &kNoBackoffPolicy);
1282 1289
1283 GURL test_url(base::StringPrintf("%s/extension.crx", url_prefix.c_str())); 1290 GURL test_url(base::StringPrintf("%s/extension.crx", url_prefix.c_str()));
1284 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 1291 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1285 std::string hash; 1292 std::string hash;
1286 Version version("0.0.1"); 1293 Version version("0.0.1");
1287 std::set<int> requests; 1294 std::set<int> requests;
1288 requests.insert(0); 1295 requests.insert(0);
1289 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch( 1296 std::unique_ptr<ExtensionDownloader::ExtensionFetch> fetch(
1290 new ExtensionDownloader::ExtensionFetch( 1297 new ExtensionDownloader::ExtensionFetch(id, test_url, hash,
1291 id, test_url, hash, version.GetString(), requests)); 1298 version.GetString(), requests));
1292 updater.downloader_->FetchUpdatedExtension(std::move(fetch)); 1299 updater.downloader_->FetchUpdatedExtension(std::move(fetch));
1293 1300
1294 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); 1301 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId);
1295 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 1302 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
1296 EXPECT_EQ(kExpectedLoadFlags, fetcher->GetLoadFlags()); 1303 EXPECT_EQ(kExpectedLoadFlags, fetcher->GetLoadFlags());
1297 1304
1298 // Fake a 403 response. 1305 // Fake a 403 response.
1299 fetcher->set_url(test_url); 1306 fetcher->set_url(test_url);
1300 fetcher->set_status(net::URLRequestStatus()); 1307 fetcher->set_status(net::URLRequestStatus());
1301 fetcher->set_response_code(403); 1308 fetcher->set_response_code(403);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 std::string id2 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; 1476 std::string id2 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
1470 1477
1471 std::string hash1; 1478 std::string hash1;
1472 std::string hash2; 1479 std::string hash2;
1473 1480
1474 std::string version1 = "0.1"; 1481 std::string version1 = "0.1";
1475 std::string version2 = "0.1"; 1482 std::string version2 = "0.1";
1476 std::set<int> requests; 1483 std::set<int> requests;
1477 requests.insert(0); 1484 requests.insert(0);
1478 // Start two fetches 1485 // Start two fetches
1479 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch1( 1486 std::unique_ptr<ExtensionDownloader::ExtensionFetch> fetch1(
1480 new ExtensionDownloader::ExtensionFetch( 1487 new ExtensionDownloader::ExtensionFetch(id1, url1, hash1, version1,
1481 id1, url1, hash1, version1, requests)); 1488 requests));
1482 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch2( 1489 std::unique_ptr<ExtensionDownloader::ExtensionFetch> fetch2(
1483 new ExtensionDownloader::ExtensionFetch( 1490 new ExtensionDownloader::ExtensionFetch(id2, url2, hash2, version2,
1484 id2, url2, hash2, version2, requests)); 1491 requests));
1485 updater.downloader_->FetchUpdatedExtension(std::move(fetch1)); 1492 updater.downloader_->FetchUpdatedExtension(std::move(fetch1));
1486 updater.downloader_->FetchUpdatedExtension(std::move(fetch2)); 1493 updater.downloader_->FetchUpdatedExtension(std::move(fetch2));
1487 1494
1488 // Make the first fetch complete. 1495 // Make the first fetch complete.
1489 base::FilePath extension_file_path(FILE_PATH_LITERAL("/whatever")); 1496 base::FilePath extension_file_path(FILE_PATH_LITERAL("/whatever"));
1490 1497
1491 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); 1498 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId);
1492 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 1499 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
1493 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); 1500 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags);
1494 1501
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1768 ExtensionUpdater updater(&service, 1775 ExtensionUpdater updater(&service,
1769 service.extension_prefs(), 1776 service.extension_prefs(),
1770 service.pref_service(), 1777 service.pref_service(),
1771 service.profile(), 1778 service.profile(),
1772 kUpdateFrequencySecs, 1779 kUpdateFrequencySecs,
1773 nullptr, 1780 nullptr,
1774 service.GetDownloaderFactory()); 1781 service.GetDownloaderFactory());
1775 updater.Start(); 1782 updater.Start();
1776 updater.EnsureDownloaderCreated(); 1783 updater.EnsureDownloaderCreated();
1777 1784
1778 scoped_ptr<ManifestFetchData> fetch_data( 1785 std::unique_ptr<ManifestFetchData> fetch_data(
1779 CreateManifestFetchData(update_url)); 1786 CreateManifestFetchData(update_url));
1780 const Extension* extension = tmp[0].get(); 1787 const Extension* extension = tmp[0].get();
1781 fetch_data->AddExtension(extension->id(), extension->VersionString(), 1788 fetch_data->AddExtension(extension->id(), extension->VersionString(),
1782 &kNeverPingedData, kEmptyUpdateUrlData, 1789 &kNeverPingedData, kEmptyUpdateUrlData,
1783 std::string()); 1790 std::string());
1784 UpdateManifest::Results results; 1791 UpdateManifest::Results results;
1785 results.daystart_elapsed_seconds = 750; 1792 results.daystart_elapsed_seconds = 750;
1786 1793
1787 updater.downloader_->HandleManifestResults(fetch_data.get(), &results); 1794 updater.downloader_->HandleManifestResults(fetch_data.get(), &results);
1788 Time last_ping_day = 1795 Time last_ping_day =
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1881 // Make sure it's a power of 2. 1888 // Make sure it's a power of 2.
1882 ASSERT_TRUE(reason < 2 || !(reason & (reason - 1))) << reason; 1889 ASSERT_TRUE(reason < 2 || !(reason & (reason - 1))) << reason;
1883 found_reasons |= reason; 1890 found_reasons |= reason;
1884 } 1891 }
1885 EXPECT_EQ(disable_reasons, found_reasons); 1892 EXPECT_EQ(disable_reasons, found_reasons);
1886 } 1893 }
1887 } 1894 }
1888 } 1895 }
1889 1896
1890 protected: 1897 protected:
1891 scoped_ptr<TestExtensionPrefs> prefs_; 1898 std::unique_ptr<TestExtensionPrefs> prefs_;
1892 1899
1893 ManifestFetchData* CreateManifestFetchData(const GURL& update_url) { 1900 ManifestFetchData* CreateManifestFetchData(const GURL& update_url) {
1894 return new ManifestFetchData(update_url, 0, "", 1901 return new ManifestFetchData(update_url, 0, "",
1895 UpdateQueryParams::Get(UpdateQueryParams::CRX), 1902 UpdateQueryParams::Get(UpdateQueryParams::CRX),
1896 ManifestFetchData::PING); 1903 ManifestFetchData::PING);
1897 } 1904 }
1898 1905
1899 private: 1906 private:
1900 content::TestBrowserThreadBundle thread_bundle_; 1907 content::TestBrowserThreadBundle thread_bundle_;
1901 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; 1908 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_;
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
2117 service.set_extensions(enabled_extensions, disabled_extensions); 2124 service.set_extensions(enabled_extensions, disabled_extensions);
2118 ExtensionUpdater::CheckParams params; 2125 ExtensionUpdater::CheckParams params;
2119 updater.Start(); 2126 updater.Start();
2120 updater.CheckNow(params); 2127 updater.CheckNow(params);
2121 } 2128 }
2122 2129
2123 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { 2130 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) {
2124 net::TestURLFetcherFactory factory; 2131 net::TestURLFetcherFactory factory;
2125 MockService service(prefs_.get()); 2132 MockService service(prefs_.get());
2126 MockExtensionDownloaderDelegate delegate; 2133 MockExtensionDownloaderDelegate delegate;
2127 scoped_ptr<ExtensionDownloader> downloader( 2134 std::unique_ptr<ExtensionDownloader> downloader(
2128 new ExtensionDownloader(&delegate, service.request_context())); 2135 new ExtensionDownloader(&delegate, service.request_context()));
2129 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); 2136 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get()));
2130 2137
2131 // First, verify that adding valid extensions does invoke the callbacks on 2138 // First, verify that adding valid extensions does invoke the callbacks on
2132 // the delegate. 2139 // the delegate.
2133 std::string id = crx_file::id_util::GenerateId("foo"); 2140 std::string id = crx_file::id_util::GenerateId("foo");
2134 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); 2141 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false));
2135 EXPECT_TRUE( 2142 EXPECT_TRUE(
2136 downloader->AddPendingExtension(id, GURL("http://example.com/update"), 2143 downloader->AddPendingExtension(id, GURL("http://example.com/update"),
2137 0)); 2144 0));
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2264 // -prodversionmin (shouldn't update if browser version too old) 2271 // -prodversionmin (shouldn't update if browser version too old)
2265 // -manifests & updates arriving out of order / interleaved 2272 // -manifests & updates arriving out of order / interleaved
2266 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 2273 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
2267 // -An extension gets uninstalled while updates are in progress (so it doesn't 2274 // -An extension gets uninstalled while updates are in progress (so it doesn't
2268 // "come back from the dead") 2275 // "come back from the dead")
2269 // -An extension gets manually updated to v3 while we're downloading v2 (ie 2276 // -An extension gets manually updated to v3 while we're downloading v2 (ie
2270 // you don't get downgraded accidentally) 2277 // you don't get downgraded accidentally)
2271 // -An update manifest mentions multiple updates 2278 // -An update manifest mentions multiple updates
2272 2279
2273 } // namespace extensions 2280 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/extension_updater.h ('k') | chrome/browser/extensions/updater/local_extension_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698