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

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

Issue 434493002: OAuth2 support for Webstore downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix ExternalCache on chromeos Created 6 years, 4 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
« no previous file with comments | « chrome/browser/extensions/updater/extension_updater.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "content/public/browser/notification_service.h" 46 #include "content/public/browser/notification_service.h"
47 #include "content/public/browser/notification_source.h" 47 #include "content/public/browser/notification_source.h"
48 #include "content/public/test/test_browser_thread_bundle.h" 48 #include "content/public/test/test_browser_thread_bundle.h"
49 #include "content/public/test/test_utils.h" 49 #include "content/public/test/test_utils.h"
50 #include "extensions/browser/extension_prefs.h" 50 #include "extensions/browser/extension_prefs.h"
51 #include "extensions/browser/extension_registry.h" 51 #include "extensions/browser/extension_registry.h"
52 #include "extensions/browser/extension_system.h" 52 #include "extensions/browser/extension_system.h"
53 #include "extensions/common/extension.h" 53 #include "extensions/common/extension.h"
54 #include "extensions/common/id_util.h" 54 #include "extensions/common/id_util.h"
55 #include "extensions/common/manifest_constants.h" 55 #include "extensions/common/manifest_constants.h"
56 #include "google_apis/gaia/fake_identity_provider.h"
57 #include "google_apis/gaia/fake_oauth2_token_service.h"
56 #include "libxml/globals.h" 58 #include "libxml/globals.h"
57 #include "net/base/backoff_entry.h" 59 #include "net/base/backoff_entry.h"
58 #include "net/base/escape.h" 60 #include "net/base/escape.h"
59 #include "net/base/load_flags.h" 61 #include "net/base/load_flags.h"
62 #include "net/http/http_request_headers.h"
60 #include "net/url_request/test_url_fetcher_factory.h" 63 #include "net/url_request/test_url_fetcher_factory.h"
61 #include "net/url_request/url_request_status.h" 64 #include "net/url_request/url_request_status.h"
62 #include "testing/gmock/include/gmock/gmock.h" 65 #include "testing/gmock/include/gmock/gmock.h"
63 #include "testing/gtest/include/gtest/gtest.h" 66 #include "testing/gtest/include/gtest/gtest.h"
64 #include "url/third_party/mozilla/url_parse.h" 67 #include "url/third_party/mozilla/url_parse.h"
65 68
66 #if defined(OS_CHROMEOS) 69 #if defined(OS_CHROMEOS)
67 #include "chrome/browser/chromeos/login/users/user_manager.h" 70 #include "chrome/browser/chromeos/login/users/user_manager.h"
68 #include "chrome/browser/chromeos/settings/cros_settings.h" 71 #include "chrome/browser/chromeos/settings/cros_settings.h"
69 #include "chrome/browser/chromeos/settings/device_settings_service.h" 72 #include "chrome/browser/chromeos/settings/device_settings_service.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 118
116 const char kEmptyUpdateUrlData[] = ""; 119 const char kEmptyUpdateUrlData[] = "";
117 120
118 const char kAuthUserQueryKey[] = "authuser"; 121 const char kAuthUserQueryKey[] = "authuser";
119 122
120 int kExpectedLoadFlags = 123 int kExpectedLoadFlags =
121 net::LOAD_DO_NOT_SEND_COOKIES | 124 net::LOAD_DO_NOT_SEND_COOKIES |
122 net::LOAD_DO_NOT_SAVE_COOKIES | 125 net::LOAD_DO_NOT_SAVE_COOKIES |
123 net::LOAD_DISABLE_CACHE; 126 net::LOAD_DISABLE_CACHE;
124 127
125 int kExpectedLoadFlagsForProtectedDownload = net::LOAD_DISABLE_CACHE; 128 int kExpectedLoadFlagsForDownloadWithCookies = net::LOAD_DISABLE_CACHE;
126 129
127 const ManifestFetchData::PingData kNeverPingedData( 130 const ManifestFetchData::PingData kNeverPingedData(
128 ManifestFetchData::kNeverPinged, ManifestFetchData::kNeverPinged, true); 131 ManifestFetchData::kNeverPinged, ManifestFetchData::kNeverPinged, true);
129 132
130 class MockExtensionDownloaderDelegate : public ExtensionDownloaderDelegate { 133 class MockExtensionDownloaderDelegate : public ExtensionDownloaderDelegate {
131 public: 134 public:
132 MOCK_METHOD4(OnExtensionDownloadFailed, void(const std::string&, 135 MOCK_METHOD4(OnExtensionDownloadFailed, void(const std::string&,
133 Error, 136 Error,
134 const PingResult&, 137 const PingResult&,
135 const std::set<int>&)); 138 const std::set<int>&));
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 SetupPendingExtensionManagerForTest(1, GURL(update_url), 599 SetupPendingExtensionManagerForTest(1, GURL(update_url),
597 pending_extension_manager); 600 pending_extension_manager);
598 } else { 601 } else {
599 service.CreateTestExtensions(1, 1, &extensions, &update_url, 602 service.CreateTestExtensions(1, 1, &extensions, &update_url,
600 Manifest::INTERNAL); 603 Manifest::INTERNAL);
601 service.set_extensions(extensions, ExtensionList()); 604 service.set_extensions(extensions, ExtensionList());
602 } 605 }
603 606
604 // Set up and start the updater. 607 // Set up and start the updater.
605 net::TestURLFetcherFactory factory; 608 net::TestURLFetcherFactory factory;
606 ExtensionUpdater updater( 609 ExtensionUpdater updater(&service,
607 &service, service.extension_prefs(), service.pref_service(), 610 service.extension_prefs(),
608 service.profile(), 60*60*24, NULL); 611 service.pref_service(),
612 service.profile(),
613 60 * 60 * 24,
614 NULL,
615 make_scoped_ptr<IdentityProvider>(NULL));
609 updater.Start(); 616 updater.Start();
610 617
611 // Tell the update that it's time to do update checks. 618 // Tell the update that it's time to do update checks.
612 EXPECT_EQ(0u, observer.StartedCount()); 619 EXPECT_EQ(0u, observer.StartedCount());
613 SimulateTimerFired(&updater); 620 SimulateTimerFired(&updater);
614 EXPECT_EQ(1u, observer.StartedCount()); 621 EXPECT_EQ(1u, observer.StartedCount());
615 622
616 // Get the url our mock fetcher was asked to fetch. 623 // Get the url our mock fetcher was asked to fetch.
617 net::TestURLFetcher* fetcher = 624 net::TestURLFetcher* fetcher =
618 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 625 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 EXPECT_EQ(id, params["id"]); 692 EXPECT_EQ(id, params["id"]);
686 EXPECT_EQ(version, params["v"]); 693 EXPECT_EQ(version, params["v"]);
687 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); 694 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]);
688 } 695 }
689 696
690 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { 697 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) {
691 net::TestURLFetcherFactory factory; 698 net::TestURLFetcherFactory factory;
692 699
693 MockService service(prefs_.get()); 700 MockService service(prefs_.get());
694 MockExtensionDownloaderDelegate delegate; 701 MockExtensionDownloaderDelegate delegate;
695 ExtensionDownloader downloader(&delegate, service.request_context()); 702 ExtensionDownloader downloader(&delegate, service.request_context(), NULL);
696 ExtensionList extensions; 703 ExtensionList extensions;
697 std::string url(gallery_url); 704 std::string url(gallery_url);
698 705
699 service.CreateTestExtensions(1, 1, &extensions, &url, Manifest::INTERNAL); 706 service.CreateTestExtensions(1, 1, &extensions, &url, Manifest::INTERNAL);
700 707
701 const std::string& id = extensions[0]->id(); 708 const std::string& id = extensions[0]->id();
702 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)); 709 EXPECT_CALL(delegate, GetPingDataForExtension(id, _));
703 710
704 downloader.AddExtension(*extensions[0].get(), 0); 711 downloader.AddExtension(*extensions[0].get(), 0);
705 downloader.StartAllPending(NULL); 712 downloader.StartAllPending(NULL);
(...skipping 21 matching lines...) Expand all
727 std::map<std::string, std::string> params; 734 std::map<std::string, std::string> params;
728 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params); 735 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params);
729 EXPECT_EQ(id, params["id"]); 736 EXPECT_EQ(id, params["id"]);
730 EXPECT_EQ(version, params["v"]); 737 EXPECT_EQ(version, params["v"]);
731 EXPECT_EQ(install_source, params["installsource"]); 738 EXPECT_EQ(install_source, params["installsource"]);
732 } 739 }
733 740
734 void TestDetermineUpdates() { 741 void TestDetermineUpdates() {
735 TestingProfile profile; 742 TestingProfile profile;
736 MockExtensionDownloaderDelegate delegate; 743 MockExtensionDownloaderDelegate delegate;
737 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); 744 ExtensionDownloader downloader(
745 &delegate, profile.GetRequestContext(), NULL);
738 746
739 // Check passing an empty list of parse results to DetermineUpdates 747 // Check passing an empty list of parse results to DetermineUpdates
740 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 748 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
741 UpdateManifest::Results updates; 749 UpdateManifest::Results updates;
742 std::vector<int> updateable; 750 std::vector<int> updateable;
743 downloader.DetermineUpdates(fetch_data, updates, &updateable); 751 downloader.DetermineUpdates(fetch_data, updates, &updateable);
744 EXPECT_TRUE(updateable.empty()); 752 EXPECT_TRUE(updateable.empty());
745 753
746 // Create two updates - expect that DetermineUpdates will return the first 754 // Create two updates - expect that DetermineUpdates will return the first
747 // one (v1.0 installed, v1.1 available) but not the second one (both 755 // one (v1.0 installed, v1.1 available) but not the second one (both
(...skipping 22 matching lines...) Expand all
770 778
771 void TestDetermineUpdatesPending() { 779 void TestDetermineUpdatesPending() {
772 // Create a set of test extensions 780 // Create a set of test extensions
773 ServiceForManifestTests service(prefs_.get()); 781 ServiceForManifestTests service(prefs_.get());
774 PendingExtensionManager* pending_extension_manager = 782 PendingExtensionManager* pending_extension_manager =
775 service.pending_extension_manager(); 783 service.pending_extension_manager();
776 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); 784 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager);
777 785
778 TestingProfile profile; 786 TestingProfile profile;
779 MockExtensionDownloaderDelegate delegate; 787 MockExtensionDownloaderDelegate delegate;
780 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); 788 ExtensionDownloader downloader(
789 &delegate, profile.GetRequestContext(), NULL);
781 790
782 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 791 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
783 UpdateManifest::Results updates; 792 UpdateManifest::Results updates;
784 793
785 std::list<std::string> ids_for_update_check; 794 std::list<std::string> ids_for_update_check;
786 pending_extension_manager->GetPendingIdsForUpdateCheck( 795 pending_extension_manager->GetPendingIdsForUpdateCheck(
787 &ids_for_update_check); 796 &ids_for_update_check);
788 797
789 std::list<std::string>::const_iterator it; 798 std::list<std::string>::const_iterator it;
790 for (it = ids_for_update_check.begin(); 799 for (it = ids_for_update_check.begin();
(...skipping 18 matching lines...) Expand all
809 EXPECT_EQ(static_cast<int>(i), updateable[i]); 818 EXPECT_EQ(static_cast<int>(i), updateable[i]);
810 } 819 }
811 } 820 }
812 821
813 void TestMultipleManifestDownloading() { 822 void TestMultipleManifestDownloading() {
814 net::TestURLFetcherFactory factory; 823 net::TestURLFetcherFactory factory;
815 factory.set_remove_fetcher_on_delete(true); 824 factory.set_remove_fetcher_on_delete(true);
816 net::TestURLFetcher* fetcher = NULL; 825 net::TestURLFetcher* fetcher = NULL;
817 MockService service(prefs_.get()); 826 MockService service(prefs_.get());
818 MockExtensionDownloaderDelegate delegate; 827 MockExtensionDownloaderDelegate delegate;
819 ExtensionDownloader downloader(&delegate, service.request_context()); 828 ExtensionDownloader downloader(&delegate, service.request_context(), NULL);
820 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); 829 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy);
821 830
822 GURL kUpdateUrl("http://localhost/manifest1"); 831 GURL kUpdateUrl("http://localhost/manifest1");
823 832
824 scoped_ptr<ManifestFetchData> fetch1(new ManifestFetchData(kUpdateUrl, 0)); 833 scoped_ptr<ManifestFetchData> fetch1(new ManifestFetchData(kUpdateUrl, 0));
825 scoped_ptr<ManifestFetchData> fetch2(new ManifestFetchData(kUpdateUrl, 0)); 834 scoped_ptr<ManifestFetchData> fetch2(new ManifestFetchData(kUpdateUrl, 0));
826 scoped_ptr<ManifestFetchData> fetch3(new ManifestFetchData(kUpdateUrl, 0)); 835 scoped_ptr<ManifestFetchData> fetch3(new ManifestFetchData(kUpdateUrl, 0));
827 scoped_ptr<ManifestFetchData> fetch4(new ManifestFetchData(kUpdateUrl, 0)); 836 scoped_ptr<ManifestFetchData> fetch4(new ManifestFetchData(kUpdateUrl, 0));
828 ManifestFetchData::PingData zeroDays(0, 0, true); 837 ManifestFetchData::PingData zeroDays(0, 0, true);
829 fetch1->AddExtension( 838 fetch1->AddExtension(
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 if (fetcher) 958 if (fetcher)
950 ADD_FAILURE() << "Unexpected fetch: " << fetcher->GetOriginalURL(); 959 ADD_FAILURE() << "Unexpected fetch: " << fetcher->GetOriginalURL();
951 } 960 }
952 961
953 void TestManifestRetryDownloading() { 962 void TestManifestRetryDownloading() {
954 net::TestURLFetcherFactory factory; 963 net::TestURLFetcherFactory factory;
955 net::TestURLFetcher* fetcher = NULL; 964 net::TestURLFetcher* fetcher = NULL;
956 NotificationsObserver observer; 965 NotificationsObserver observer;
957 MockService service(prefs_.get()); 966 MockService service(prefs_.get());
958 MockExtensionDownloaderDelegate delegate; 967 MockExtensionDownloaderDelegate delegate;
959 ExtensionDownloader downloader(&delegate, service.request_context()); 968 ExtensionDownloader downloader(&delegate, service.request_context(), NULL);
960 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); 969 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy);
961 970
962 GURL kUpdateUrl("http://localhost/manifest1"); 971 GURL kUpdateUrl("http://localhost/manifest1");
963 972
964 scoped_ptr<ManifestFetchData> fetch(new ManifestFetchData(kUpdateUrl, 0)); 973 scoped_ptr<ManifestFetchData> fetch(new ManifestFetchData(kUpdateUrl, 0));
965 ManifestFetchData::PingData zeroDays(0, 0, true); 974 ManifestFetchData::PingData zeroDays(0, 0, true);
966 fetch->AddExtension( 975 fetch->AddExtension(
967 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); 976 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string());
968 977
969 // This will start the first fetcher. 978 // This will start the first fetcher.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 RunUntilIdle(); 1031 RunUntilIdle();
1023 1032
1024 Mock::VerifyAndClearExpectations(&delegate); 1033 Mock::VerifyAndClearExpectations(&delegate);
1025 } 1034 }
1026 1035
1027 void TestSingleExtensionDownloading(bool pending, bool retry, bool fail) { 1036 void TestSingleExtensionDownloading(bool pending, bool retry, bool fail) {
1028 net::TestURLFetcherFactory factory; 1037 net::TestURLFetcherFactory factory;
1029 net::TestURLFetcher* fetcher = NULL; 1038 net::TestURLFetcher* fetcher = NULL;
1030 scoped_ptr<ServiceForDownloadTests> service( 1039 scoped_ptr<ServiceForDownloadTests> service(
1031 new ServiceForDownloadTests(prefs_.get())); 1040 new ServiceForDownloadTests(prefs_.get()));
1032 ExtensionUpdater updater(service.get(), service->extension_prefs(), 1041 ExtensionUpdater updater(service.get(),
1042 service->extension_prefs(),
1033 service->pref_service(), 1043 service->pref_service(),
1034 service->profile(), 1044 service->profile(),
1035 kUpdateFrequencySecs, 1045 kUpdateFrequencySecs,
1036 NULL); 1046 NULL,
1047 make_scoped_ptr<IdentityProvider>(NULL));
1037 updater.Start(); 1048 updater.Start();
1038 MockExtensionDownloaderDelegate delegate; 1049 MockExtensionDownloaderDelegate delegate;
1039 delegate.DelegateTo(&updater); 1050 delegate.DelegateTo(&updater);
1040 ResetDownloader( 1051 ResetDownloader(
1041 &updater, 1052 &updater,
1042 new ExtensionDownloader(&delegate, service->request_context())); 1053 new ExtensionDownloader(&delegate, service->request_context(), NULL));
1043 updater.downloader_->extensions_queue_.set_backoff_policy( 1054 updater.downloader_->extensions_queue_.set_backoff_policy(
1044 &kNoBackoffPolicy); 1055 &kNoBackoffPolicy);
1045 1056
1046 GURL test_url("http://localhost/extension.crx"); 1057 GURL test_url("http://localhost/extension.crx");
1047 1058
1048 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 1059 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1049 std::string hash; 1060 std::string hash;
1050 Version version("0.0.1"); 1061 Version version("0.0.1");
1051 std::set<int> requests; 1062 std::set<int> requests;
1052 requests.insert(0); 1063 requests.insert(0);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 // Expect that ExtensionUpdater asked the mock extensions service to 1129 // Expect that ExtensionUpdater asked the mock extensions service to
1119 // install a file with the test data for the right id. 1130 // install a file with the test data for the right id.
1120 EXPECT_EQ(id, service->extension_id()); 1131 EXPECT_EQ(id, service->extension_id());
1121 base::FilePath tmpfile_path = service->install_path(); 1132 base::FilePath tmpfile_path = service->install_path();
1122 EXPECT_FALSE(tmpfile_path.empty()); 1133 EXPECT_FALSE(tmpfile_path.empty());
1123 EXPECT_EQ(extension_file_path, tmpfile_path); 1134 EXPECT_EQ(extension_file_path, tmpfile_path);
1124 } 1135 }
1125 } 1136 }
1126 1137
1127 // Update a single extension in an environment where the download request 1138 // Update a single extension in an environment where the download request
1128 // initially responds with a 403 status. Expect the fetcher to automatically 1139 // initially responds with a 403 status. If |identity_provider| is not NULL,
1129 // retry with cookies enabled. 1140 // this will first expect a request which includes an Authorization header
1130 void TestSingleProtectedExtensionDownloading(bool use_https, 1141 // with an OAuth2 bearer token; otherwise, or if OAuth2 failure is simulated,
1131 bool fail, 1142 // this expects the downloader to fall back onto cookie-based credentials.
1132 int max_authuser, 1143 void TestProtectedDownload(
1133 int valid_authuser) { 1144 const std::string& url_prefix,
1145 bool enable_oauth2,
1146 bool succeed_with_oauth2,
1147 int valid_authuser,
1148 int max_authuser) {
1149 const char kFakeAccountId[] = "bobloblaw@lawblog.example.com";
1150 const char kFakeOAuth2Token[] = "ce n'est pas un jeton";
1151
1134 net::TestURLFetcherFactory factory; 1152 net::TestURLFetcherFactory factory;
1135 net::TestURLFetcher* fetcher = NULL; 1153 net::TestURLFetcher* fetcher = NULL;
1136 scoped_ptr<ServiceForDownloadTests> service( 1154 scoped_ptr<ServiceForDownloadTests> service(
1137 new ServiceForDownloadTests(prefs_.get())); 1155 new ServiceForDownloadTests(prefs_.get()));
1138 ExtensionUpdater updater(service.get(), service->extension_prefs(), 1156 ExtensionUpdater updater(service.get(),
1157 service->extension_prefs(),
1139 service->pref_service(), 1158 service->pref_service(),
1140 service->profile(), 1159 service->profile(),
1141 kUpdateFrequencySecs, 1160 kUpdateFrequencySecs,
1142 NULL); 1161 NULL,
1162 make_scoped_ptr<IdentityProvider>(NULL));
1143 updater.Start(); 1163 updater.Start();
1164
1165 scoped_ptr<FakeOAuth2TokenService> fake_token_service;
1166 scoped_ptr<FakeIdentityProvider> fake_identity_provider;
1167 if (enable_oauth2) {
1168 fake_token_service.reset(new FakeOAuth2TokenService());
1169 fake_identity_provider.reset(new FakeIdentityProvider(
1170 fake_token_service.get()));
1171 fake_identity_provider->LogIn(kFakeAccountId);
1172 fake_token_service->AddAccount(kFakeAccountId);
1173 }
1174
1144 ResetDownloader( 1175 ResetDownloader(
1145 &updater, 1176 &updater,
1146 new ExtensionDownloader(&updater, service->request_context())); 1177 new ExtensionDownloader(&updater,
1178 service->request_context(),
1179 fake_identity_provider.get()));
1147 updater.downloader_->extensions_queue_.set_backoff_policy( 1180 updater.downloader_->extensions_queue_.set_backoff_policy(
1148 &kNoBackoffPolicy); 1181 &kNoBackoffPolicy);
1149 1182
1150 GURL test_url(use_https ? "https://localhost/extension.crx" : 1183 GURL test_url(base::StringPrintf("%s/extension.crx", url_prefix.c_str()));
1151 "http://localhost/extension.crx");
1152
1153 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 1184 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1154 std::string hash; 1185 std::string hash;
1155 Version version("0.0.1"); 1186 Version version("0.0.1");
1156 std::set<int> requests; 1187 std::set<int> requests;
1157 requests.insert(0); 1188 requests.insert(0);
1158 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch( 1189 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch(
1159 new ExtensionDownloader::ExtensionFetch( 1190 new ExtensionDownloader::ExtensionFetch(
1160 id, test_url, hash, version.GetString(), requests)); 1191 id, test_url, hash, version.GetString(), requests));
1161 updater.downloader_->FetchUpdatedExtension(fetch.Pass()); 1192 updater.downloader_->FetchUpdatedExtension(fetch.Pass());
1162 1193
1163 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); 1194 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId);
1164 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 1195 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
1165 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); 1196 EXPECT_EQ(kExpectedLoadFlags, fetcher->GetLoadFlags());
1166 1197
1167 // Fake a 403 response. 1198 // Fake a 403 response.
1168 fetcher->set_url(test_url); 1199 fetcher->set_url(test_url);
1169 fetcher->set_status(net::URLRequestStatus()); 1200 fetcher->set_status(net::URLRequestStatus());
1170 fetcher->set_response_code(403); 1201 fetcher->set_response_code(403);
1171 fetcher->delegate()->OnURLFetchComplete(fetcher); 1202 fetcher->delegate()->OnURLFetchComplete(fetcher);
1203 if (fake_token_service) {
1204 fake_token_service->IssueAllTokensForAccount(
1205 kFakeAccountId, kFakeOAuth2Token, base::Time::Now());
1206 }
1172 RunUntilIdle(); 1207 RunUntilIdle();
1173 1208
1174 // Verify that the fetcher has been switched to protected download mode 1209 bool using_oauth2 = false;
1175 // so that cookies would be sent with the next request (https only). 1210 int expected_load_flags = kExpectedLoadFlags;
1211 // Verify that the fetch has had its credentials properly incremented.
1176 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); 1212 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId);
1177 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 1213 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
1178 if (use_https) { 1214 net::HttpRequestHeaders fetch_headers;
1179 EXPECT_TRUE( 1215 fetcher->GetExtraRequestHeaders(&fetch_headers);
1180 fetcher->GetLoadFlags() == kExpectedLoadFlagsForProtectedDownload); 1216 // If the download URL is not https, no credentials should be provided.
1217 if (!test_url.SchemeIsSecure()) {
1218 // No cookies.
1219 EXPECT_EQ(kExpectedLoadFlags, fetcher->GetLoadFlags());
1220 // No Authorization header.
1221 EXPECT_FALSE(fetch_headers.HasHeader(
1222 net::HttpRequestHeaders::kAuthorization));
1223 expected_load_flags = kExpectedLoadFlags;
1181 } else { 1224 } else {
1182 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); 1225 // HTTPS is in use, so credentials are allowed.
1226 if (enable_oauth2 && test_url.DomainIs("google.com")) {
1227 // If an IdentityProvider is present and the URL is a google.com
1228 // URL, the fetcher should be in OAuth2 mode after the intitial
1229 // challenge.
1230 EXPECT_TRUE(fetch_headers.HasHeader(
1231 net::HttpRequestHeaders::kAuthorization));
1232 std::string expected_header_value = base::StringPrintf("Bearer %s",
1233 kFakeOAuth2Token);
1234 std::string actual_header_value;
1235 fetch_headers.GetHeader(net::HttpRequestHeaders::kAuthorization,
1236 &actual_header_value);
1237 EXPECT_EQ(expected_header_value, actual_header_value);
1238 using_oauth2 = true;
1239 } else {
1240 // No IdentityProvider (or no google.com), so expect cookies instead of
1241 // an Authorization header.
1242 EXPECT_FALSE(fetch_headers.HasHeader(
1243 net::HttpRequestHeaders::kAuthorization));
1244 EXPECT_EQ(kExpectedLoadFlagsForDownloadWithCookies,
1245 fetcher->GetLoadFlags());
1246 expected_load_flags = kExpectedLoadFlagsForDownloadWithCookies;
1247 }
1183 } 1248 }
1184 1249
1185 // Attempt to fetch again after the auth failure. 1250 bool success = false;
1186 bool succeed = !fail; 1251 if (using_oauth2) {
1187 if (fail) { 1252 if (succeed_with_oauth2) {
1188 // Do not simulate incremental authuser retries. 1253 success = true;
1189 if (max_authuser == 0) { 1254 } else {
1190 // Fail and verify that the fetch queue is cleared. 1255 // Simulate OAuth2 failure and ensure that we fall back on cookies.
1191 fetcher->set_url(test_url); 1256 fetcher->set_url(test_url);
1192 fetcher->set_status(net::URLRequestStatus()); 1257 fetcher->set_status(net::URLRequestStatus());
1193 fetcher->set_response_code(401); 1258 fetcher->set_response_code(403);
1194 fetcher->delegate()->OnURLFetchComplete(fetcher); 1259 fetcher->delegate()->OnURLFetchComplete(fetcher);
1195 RunUntilIdle(); 1260 RunUntilIdle();
1196 1261
1197 EXPECT_EQ(0U, updater.downloader_->extensions_queue_.active_request()); 1262 const ExtensionDownloader::ExtensionFetch& fetch =
1198 return; 1263 *updater.downloader_->extensions_queue_.active_request();
1264 EXPECT_EQ(0, GetAuthUserQueryValue(fetch.url));
1265 EXPECT_EQ(ExtensionDownloader::ExtensionFetch::CREDENTIALS_COOKIES,
1266 fetch.credentials);
1267
1268 fetcher = factory.GetFetcherByID(
1269 ExtensionDownloader::kExtensionFetcherId);
1270 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
1271 fetcher->GetExtraRequestHeaders(&fetch_headers);
1272 EXPECT_FALSE(fetch_headers.HasHeader(
1273 net::HttpRequestHeaders::kAuthorization));
1274 EXPECT_EQ(kExpectedLoadFlagsForDownloadWithCookies,
1275 fetcher->GetLoadFlags());
1276 expected_load_flags = kExpectedLoadFlagsForDownloadWithCookies;
1199 } 1277 }
1278 }
1200 1279
1201 // Simulate incremental authuser retries. 1280 if (!success) {
1202 for (int user_index = 0; user_index <= max_authuser; ++user_index) { 1281 // Not yet ready to simulate a successful fetch. At this point we begin
1282 // simulating cookie-based authentication with increasing values of
1283 // authuser (starting from 0.)
1284 int user_index = 0;
1285 for (; user_index <= max_authuser; ++user_index) {
1203 const ExtensionDownloader::ExtensionFetch& fetch = 1286 const ExtensionDownloader::ExtensionFetch& fetch =
1204 *updater.downloader_->extensions_queue_.active_request(); 1287 *updater.downloader_->extensions_queue_.active_request();
1205 EXPECT_EQ(user_index, GetAuthUserQueryValue(fetch.url)); 1288 EXPECT_EQ(user_index, GetAuthUserQueryValue(fetch.url));
1206 if (user_index == valid_authuser) { 1289 if (user_index == valid_authuser) {
1207 succeed = true; 1290 success = true;
1208 break; 1291 break;
1209 } 1292 }
1293 // Simulate an authorization failure which should elicit an increment
1294 // of the authuser value.
1210 fetcher = 1295 fetcher =
1211 factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); 1296 factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId);
1212 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 1297 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
1298 EXPECT_EQ(expected_load_flags, fetcher->GetLoadFlags());
1213 fetcher->set_url(fetch.url); 1299 fetcher->set_url(fetch.url);
1214 fetcher->set_status(net::URLRequestStatus()); 1300 fetcher->set_status(net::URLRequestStatus());
1215 fetcher->set_response_code(403); 1301 fetcher->set_response_code(403);
1216 fetcher->delegate()->OnURLFetchComplete(fetcher); 1302 fetcher->delegate()->OnURLFetchComplete(fetcher);
1217 RunUntilIdle(); 1303 RunUntilIdle();
1218 } 1304 }
1305
1306 // Simulate exhaustion of all available authusers.
1307 if (!success && user_index > max_authuser) {
1308 const ExtensionDownloader::ExtensionFetch& fetch =
1309 *updater.downloader_->extensions_queue_.active_request();
1310 fetcher =
1311 factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId);
1312 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
1313 fetcher->set_url(fetch.url);
1314 fetcher->set_status(net::URLRequestStatus());
1315 fetcher->set_response_code(401);
1316 fetcher->delegate()->OnURLFetchComplete(fetcher);
1317 RunUntilIdle();
1318 }
1219 } 1319 }
1220 1320
1221 // Succeed 1321 // Simulate successful authorization with a 200 response.
1222 if (succeed) { 1322 if (success) {
1223 fetcher = 1323 fetcher =
1224 factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); 1324 factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId);
1225 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 1325 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
1226 base::FilePath extension_file_path(FILE_PATH_LITERAL("/whatever")); 1326 base::FilePath extension_file_path(FILE_PATH_LITERAL("/whatever"));
1227 fetcher->set_url(test_url); 1327 fetcher->set_url(test_url);
1228 fetcher->set_status(net::URLRequestStatus()); 1328 fetcher->set_status(net::URLRequestStatus());
1229 fetcher->set_response_code(200); 1329 fetcher->set_response_code(200);
1230 fetcher->SetResponseFilePath(extension_file_path); 1330 fetcher->SetResponseFilePath(extension_file_path);
1231 fetcher->delegate()->OnURLFetchComplete(fetcher); 1331 fetcher->delegate()->OnURLFetchComplete(fetcher);
1232 RunUntilIdle(); 1332 RunUntilIdle();
1233 1333
1234 // Verify installation would proceed as normal. 1334 // Verify installation would proceed as normal.
1235 EXPECT_EQ(id, service->extension_id()); 1335 EXPECT_EQ(id, service->extension_id());
1236 base::FilePath tmpfile_path = service->install_path(); 1336 base::FilePath tmpfile_path = service->install_path();
1237 EXPECT_FALSE(tmpfile_path.empty()); 1337 EXPECT_FALSE(tmpfile_path.empty());
1238 EXPECT_EQ(extension_file_path, tmpfile_path); 1338 EXPECT_EQ(extension_file_path, tmpfile_path);
1239 } 1339 }
1240 } 1340 }
1241 1341
1242 // Two extensions are updated. If |updates_start_running| is true, the 1342 // Two extensions are updated. If |updates_start_running| is true, the
1243 // mock extensions service has UpdateExtension(...) return true, and 1343 // mock extensions service has UpdateExtension(...) return true, and
1244 // the test is responsible for creating fake CrxInstallers. Otherwise, 1344 // the test is responsible for creating fake CrxInstallers. Otherwise,
1245 // UpdateExtension() returns false, signaling install failures. 1345 // UpdateExtension() returns false, signaling install failures.
1246 void TestMultipleExtensionDownloading(bool updates_start_running) { 1346 void TestMultipleExtensionDownloading(bool updates_start_running) {
1247 net::TestURLFetcherFactory factory; 1347 net::TestURLFetcherFactory factory;
1248 net::TestURLFetcher* fetcher = NULL; 1348 net::TestURLFetcher* fetcher = NULL;
1249 ServiceForDownloadTests service(prefs_.get()); 1349 ServiceForDownloadTests service(prefs_.get());
1250 ExtensionUpdater updater( 1350 ExtensionUpdater updater(&service,
1251 &service, service.extension_prefs(), service.pref_service(), 1351 service.extension_prefs(),
1252 service.profile(), kUpdateFrequencySecs, NULL); 1352 service.pref_service(),
1353 service.profile(),
1354 kUpdateFrequencySecs,
1355 NULL,
1356 make_scoped_ptr<IdentityProvider>(NULL));
1253 updater.Start(); 1357 updater.Start();
1254 ResetDownloader( 1358 ResetDownloader(
1255 &updater, 1359 &updater,
1256 new ExtensionDownloader(&updater, service.request_context())); 1360 new ExtensionDownloader(&updater, service.request_context(), NULL));
1257 updater.downloader_->extensions_queue_.set_backoff_policy( 1361 updater.downloader_->extensions_queue_.set_backoff_policy(
1258 &kNoBackoffPolicy); 1362 &kNoBackoffPolicy);
1259 1363
1260 EXPECT_FALSE(updater.crx_install_is_running_); 1364 EXPECT_FALSE(updater.crx_install_is_running_);
1261 1365
1262 GURL url1("http://localhost/extension1.crx"); 1366 GURL url1("http://localhost/extension1.crx");
1263 GURL url2("http://localhost/extension2.crx"); 1367 GURL url2("http://localhost/extension2.crx");
1264 1368
1265 std::string id1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 1369 std::string id1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1266 std::string id2 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; 1370 std::string id2 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 prefs->SetLastActivePingDay(id, now - TimeDelta::FromSeconds(15)); 1555 prefs->SetLastActivePingDay(id, now - TimeDelta::FromSeconds(15));
1452 } else if (active_ping_days > 0) { 1556 } else if (active_ping_days > 0) {
1453 Time last_active_ping_day = now - 1557 Time last_active_ping_day = now -
1454 TimeDelta::FromDays(active_ping_days) - 1558 TimeDelta::FromDays(active_ping_days) -
1455 TimeDelta::FromSeconds(15); 1559 TimeDelta::FromSeconds(15);
1456 prefs->SetLastActivePingDay(id, last_active_ping_day); 1560 prefs->SetLastActivePingDay(id, last_active_ping_day);
1457 } 1561 }
1458 if (active_bit) 1562 if (active_bit)
1459 prefs->SetActiveBit(id, true); 1563 prefs->SetActiveBit(id, true);
1460 1564
1461 ExtensionUpdater updater( 1565 ExtensionUpdater updater(&service,
1462 &service, service.extension_prefs(), service.pref_service(), 1566 service.extension_prefs(),
1463 service.profile(), kUpdateFrequencySecs, NULL); 1567 service.pref_service(),
1568 service.profile(),
1569 kUpdateFrequencySecs,
1570 NULL,
1571 make_scoped_ptr<IdentityProvider>(NULL));
1464 ExtensionUpdater::CheckParams params; 1572 ExtensionUpdater::CheckParams params;
1465 updater.Start(); 1573 updater.Start();
1466 updater.CheckNow(params); 1574 updater.CheckNow(params);
1467 1575
1468 // Make the updater do manifest fetching, and note the urls it tries to 1576 // Make the updater do manifest fetching, and note the urls it tries to
1469 // fetch. 1577 // fetch.
1470 std::vector<GURL> fetched_urls; 1578 std::vector<GURL> fetched_urls;
1471 net::TestURLFetcher* fetcher = 1579 net::TestURLFetcher* fetcher =
1472 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 1580 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
1473 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 1581 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 // the first time we fetched the extension, or 2) We sent a ping value of 1652 // the first time we fetched the extension, or 2) We sent a ping value of
1545 // >= 1 day for the extension. 1653 // >= 1 day for the extension.
1546 void TestHandleManifestResults() { 1654 void TestHandleManifestResults() {
1547 ServiceForManifestTests service(prefs_.get()); 1655 ServiceForManifestTests service(prefs_.get());
1548 GURL update_url("http://www.google.com/manifest"); 1656 GURL update_url("http://www.google.com/manifest");
1549 ExtensionList tmp; 1657 ExtensionList tmp;
1550 service.CreateTestExtensions(1, 1, &tmp, &update_url.spec(), 1658 service.CreateTestExtensions(1, 1, &tmp, &update_url.spec(),
1551 Manifest::INTERNAL); 1659 Manifest::INTERNAL);
1552 service.set_extensions(tmp, ExtensionList()); 1660 service.set_extensions(tmp, ExtensionList());
1553 1661
1554 ExtensionUpdater updater( 1662 ExtensionUpdater updater(&service,
1555 &service, service.extension_prefs(), service.pref_service(), 1663 service.extension_prefs(),
1556 service.profile(), kUpdateFrequencySecs, NULL); 1664 service.pref_service(),
1665 service.profile(),
1666 kUpdateFrequencySecs,
1667 NULL,
1668 make_scoped_ptr<IdentityProvider>(NULL));
1557 updater.Start(); 1669 updater.Start();
1558 ResetDownloader( 1670 ResetDownloader(
1559 &updater, 1671 &updater,
1560 new ExtensionDownloader(&updater, service.request_context())); 1672 new ExtensionDownloader(&updater, service.request_context(), NULL));
1561 1673
1562 ManifestFetchData fetch_data(update_url, 0); 1674 ManifestFetchData fetch_data(update_url, 0);
1563 const Extension* extension = tmp[0].get(); 1675 const Extension* extension = tmp[0].get();
1564 fetch_data.AddExtension(extension->id(), 1676 fetch_data.AddExtension(extension->id(),
1565 extension->VersionString(), 1677 extension->VersionString(),
1566 &kNeverPingedData, 1678 &kNeverPingedData,
1567 kEmptyUpdateUrlData, 1679 kEmptyUpdateUrlData,
1568 std::string()); 1680 std::string());
1569 UpdateManifest::Results results; 1681 UpdateManifest::Results results;
1570 results.daystart_elapsed_seconds = 750; 1682 results.daystart_elapsed_seconds = 750;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 } 1760 }
1649 1761
1650 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailureWithRetry) { 1762 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailureWithRetry) {
1651 TestSingleExtensionDownloading(false, true, true); 1763 TestSingleExtensionDownloading(false, true, true);
1652 } 1764 }
1653 1765
1654 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailurePending) { 1766 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailurePending) {
1655 TestSingleExtensionDownloading(true, false, true); 1767 TestSingleExtensionDownloading(true, false, true);
1656 } 1768 }
1657 1769
1658 TEST_F(ExtensionUpdaterTest, SingleProtectedExtensionDownloading) { 1770 TEST_F(ExtensionUpdaterTest, ProtectedDownloadCookieAuth) {
1659 TestSingleProtectedExtensionDownloading(true, false, 0, 0); 1771 TestProtectedDownload(
1772 "https://chrome.google.com/webstore/download",
1773 false, false, // No OAuth2 support
1774 0, 0);
1660 } 1775 }
1661 1776
1662 TEST_F(ExtensionUpdaterTest, SingleProtectedExtensionDownloadingFailure) { 1777 TEST_F(ExtensionUpdaterTest, ProtectedDownloadCookieFailure) {
1663 TestSingleProtectedExtensionDownloading(true, true, 0, 0); 1778 TestProtectedDownload(
1779 "https://chrome.google.com/webstore/download",
1780 false, false, // No OAuth2 support
1781 0, -1); // max_authuser=-1 simulates no valid authuser value.
1664 } 1782 }
1665 1783
1666 TEST_F(ExtensionUpdaterTest, SingleProtectedExtensionDownloadingNoHTTPS) { 1784 TEST_F(ExtensionUpdaterTest, ProtectedDownloadWithNonDefaultAuthUser1) {
1667 TestSingleProtectedExtensionDownloading(false, false, 0, 0); 1785 TestProtectedDownload("https://google.com", false, false, 1, 1);
1668 } 1786 }
1669 1787
1670 TEST_F(ExtensionUpdaterTest, 1788 TEST_F(ExtensionUpdaterTest, ProtectedDownloadWithNonDefaultAuthUser2) {
1671 SingleProtectedExtensionDownloadingWithNonDefaultAuthUser1) { 1789 TestProtectedDownload("https://google.com", false, false, 2, 2);
1672 TestSingleProtectedExtensionDownloading(true, true, 2, 1);
1673 } 1790 }
1674 1791
1675 TEST_F(ExtensionUpdaterTest, 1792 TEST_F(ExtensionUpdaterTest, ProtectedDownloadAuthUserExhaustionFailure) {
1676 SingleProtectedExtensionDownloadingWithNonDefaultAuthUser2) { 1793 TestProtectedDownload("https://google.com", false, false, 2, 5);
1677 TestSingleProtectedExtensionDownloading(true, true, 2, 2);
1678 } 1794 }
1679 1795
1680 TEST_F(ExtensionUpdaterTest, 1796 TEST_F(ExtensionUpdaterTest, ProtectedDownloadWithOAuth2Token) {
1681 SingleProtectedExtensionDownloadingAuthUserExhaustionFailure) { 1797 TestProtectedDownload(
1682 TestSingleProtectedExtensionDownloading(true, true, 2, 5); 1798 "https://google.com",
1799 true, true,
1800 0, -1);
1801 }
1802
1803 TEST_F(ExtensionUpdaterTest, ProtectedDownloadWithOAuth2Failure) {
1804 TestProtectedDownload(
1805 "https://google.com",
1806 true, false,
1807 0, -1);
1808 }
1809
1810 TEST_F(ExtensionUpdaterTest, ProtectedDownloadNoOAuth2WithNonGoogleDomain) {
1811 TestProtectedDownload(
1812 "https://not-google.com",
1813 true, true,
1814 0, -1);
1815 }
1816
1817 TEST_F(ExtensionUpdaterTest, ProtectedDownloadFailWithoutHTTPS) {
1818 TestProtectedDownload(
1819 "http://google.com",
1820 true, true,
1821 0, 0);
1683 } 1822 }
1684 1823
1685 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) { 1824 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) {
1686 TestMultipleExtensionDownloading(false); 1825 TestMultipleExtensionDownloading(false);
1687 } 1826 }
1688 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesSucceed) { 1827 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesSucceed) {
1689 TestMultipleExtensionDownloading(true); 1828 TestMultipleExtensionDownloading(true);
1690 } 1829 }
1691 1830
1692 TEST_F(ExtensionUpdaterTest, TestManifestRetryDownloading) { 1831 TEST_F(ExtensionUpdaterTest, TestManifestRetryDownloading) {
1693 TestManifestRetryDownloading(); 1832 TestManifestRetryDownloading();
1694 } 1833 }
1695 1834
1696 TEST_F(ExtensionUpdaterTest, TestGalleryRequestsWithOrganicBrand) { 1835 TEST_F(ExtensionUpdaterTest, TestGalleryRequestsWithOrganicBrand) {
1697 TestGalleryRequestsWithBrand(true); 1836 TestGalleryRequestsWithBrand(true);
1698 } 1837 }
1699 1838
1700 TEST_F(ExtensionUpdaterTest, TestGalleryRequestsWithNonOrganicBrand) { 1839 TEST_F(ExtensionUpdaterTest, TestGalleryRequestsWithNonOrganicBrand) {
1701 TestGalleryRequestsWithBrand(false); 1840 TestGalleryRequestsWithBrand(false);
1702 } 1841 }
1703 1842
1704 TEST_F(ExtensionUpdaterTest, TestHandleManifestResults) { 1843 TEST_F(ExtensionUpdaterTest, TestHandleManifestResults) {
1705 TestHandleManifestResults(); 1844 TestHandleManifestResults();
1706 } 1845 }
1707 1846
1708 TEST_F(ExtensionUpdaterTest, TestNonAutoUpdateableLocations) { 1847 TEST_F(ExtensionUpdaterTest, TestNonAutoUpdateableLocations) {
1709 net::TestURLFetcherFactory factory; 1848 net::TestURLFetcherFactory factory;
1710 ServiceForManifestTests service(prefs_.get()); 1849 ServiceForManifestTests service(prefs_.get());
1711 ExtensionUpdater updater(&service, service.extension_prefs(), 1850 ExtensionUpdater updater(&service,
1712 service.pref_service(), service.profile(), 1851 service.extension_prefs(),
1713 kUpdateFrequencySecs, NULL); 1852 service.pref_service(),
1853 service.profile(),
1854 kUpdateFrequencySecs,
1855 NULL,
1856 make_scoped_ptr<IdentityProvider>(NULL));
1714 MockExtensionDownloaderDelegate delegate; 1857 MockExtensionDownloaderDelegate delegate;
1715 // Set the downloader directly, so that all its events end up in the mock 1858 // Set the downloader directly, so that all its events end up in the mock
1716 // |delegate|. 1859 // |delegate|.
1717 ExtensionDownloader* downloader = 1860 ExtensionDownloader* downloader =
1718 new ExtensionDownloader(&delegate, service.request_context()); 1861 new ExtensionDownloader(&delegate, service.request_context(), NULL);
1719 ResetDownloader(&updater, downloader); 1862 ResetDownloader(&updater, downloader);
1720 1863
1721 // Non-internal non-external extensions should be rejected. 1864 // Non-internal non-external extensions should be rejected.
1722 ExtensionList extensions; 1865 ExtensionList extensions;
1723 service.CreateTestExtensions(1, 1, &extensions, NULL, 1866 service.CreateTestExtensions(1, 1, &extensions, NULL,
1724 Manifest::INVALID_LOCATION); 1867 Manifest::INVALID_LOCATION);
1725 service.CreateTestExtensions(2, 1, &extensions, NULL, Manifest::INTERNAL); 1868 service.CreateTestExtensions(2, 1, &extensions, NULL, Manifest::INTERNAL);
1726 ASSERT_EQ(2u, extensions.size()); 1869 ASSERT_EQ(2u, extensions.size());
1727 const std::string& updateable_id = extensions[1]->id(); 1870 const std::string& updateable_id = extensions[1]->id();
1728 1871
1729 // These expectations fail if the delegate's methods are invoked for the 1872 // These expectations fail if the delegate's methods are invoked for the
1730 // first extension, which has a non-matching id. 1873 // first extension, which has a non-matching id.
1731 EXPECT_CALL(delegate, GetUpdateUrlData(updateable_id)).WillOnce(Return("")); 1874 EXPECT_CALL(delegate, GetUpdateUrlData(updateable_id)).WillOnce(Return(""));
1732 EXPECT_CALL(delegate, GetPingDataForExtension(updateable_id, _)); 1875 EXPECT_CALL(delegate, GetPingDataForExtension(updateable_id, _));
1733 1876
1734 service.set_extensions(extensions, ExtensionList()); 1877 service.set_extensions(extensions, ExtensionList());
1735 ExtensionUpdater::CheckParams params; 1878 ExtensionUpdater::CheckParams params;
1736 updater.Start(); 1879 updater.Start();
1737 updater.CheckNow(params); 1880 updater.CheckNow(params);
1738 } 1881 }
1739 1882
1740 TEST_F(ExtensionUpdaterTest, TestUpdatingDisabledExtensions) { 1883 TEST_F(ExtensionUpdaterTest, TestUpdatingDisabledExtensions) {
1741 net::TestURLFetcherFactory factory; 1884 net::TestURLFetcherFactory factory;
1742 ServiceForManifestTests service(prefs_.get()); 1885 ServiceForManifestTests service(prefs_.get());
1743 ExtensionUpdater updater(&service, service.extension_prefs(), 1886 ExtensionUpdater updater(&service,
1744 service.pref_service(), service.profile(), 1887 service.extension_prefs(),
1745 kUpdateFrequencySecs, NULL); 1888 service.pref_service(),
1889 service.profile(),
1890 kUpdateFrequencySecs,
1891 NULL,
1892 make_scoped_ptr<IdentityProvider>(NULL));
1746 MockExtensionDownloaderDelegate delegate; 1893 MockExtensionDownloaderDelegate delegate;
1747 // Set the downloader directly, so that all its events end up in the mock 1894 // Set the downloader directly, so that all its events end up in the mock
1748 // |delegate|. 1895 // |delegate|.
1749 ExtensionDownloader* downloader = 1896 ExtensionDownloader* downloader =
1750 new ExtensionDownloader(&delegate, service.request_context()); 1897 new ExtensionDownloader(&delegate, service.request_context(), NULL);
1751 ResetDownloader(&updater, downloader); 1898 ResetDownloader(&updater, downloader);
1752 1899
1753 // Non-internal non-external extensions should be rejected. 1900 // Non-internal non-external extensions should be rejected.
1754 ExtensionList enabled_extensions; 1901 ExtensionList enabled_extensions;
1755 ExtensionList disabled_extensions; 1902 ExtensionList disabled_extensions;
1756 service.CreateTestExtensions(1, 1, &enabled_extensions, NULL, 1903 service.CreateTestExtensions(1, 1, &enabled_extensions, NULL,
1757 Manifest::INTERNAL); 1904 Manifest::INTERNAL);
1758 service.CreateTestExtensions(2, 1, &disabled_extensions, NULL, 1905 service.CreateTestExtensions(2, 1, &disabled_extensions, NULL,
1759 Manifest::INTERNAL); 1906 Manifest::INTERNAL);
1760 ASSERT_EQ(1u, enabled_extensions.size()); 1907 ASSERT_EQ(1u, enabled_extensions.size());
(...skipping 11 matching lines...) Expand all
1772 ExtensionUpdater::CheckParams params; 1919 ExtensionUpdater::CheckParams params;
1773 updater.Start(); 1920 updater.Start();
1774 updater.CheckNow(params); 1921 updater.CheckNow(params);
1775 } 1922 }
1776 1923
1777 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { 1924 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) {
1778 net::TestURLFetcherFactory factory; 1925 net::TestURLFetcherFactory factory;
1779 MockService service(prefs_.get()); 1926 MockService service(prefs_.get());
1780 MockExtensionDownloaderDelegate delegate; 1927 MockExtensionDownloaderDelegate delegate;
1781 scoped_ptr<ExtensionDownloader> downloader( 1928 scoped_ptr<ExtensionDownloader> downloader(
1782 new ExtensionDownloader(&delegate, service.request_context())); 1929 new ExtensionDownloader(&delegate, service.request_context(), NULL));
1783 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); 1930 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get()));
1784 1931
1785 // First, verify that adding valid extensions does invoke the callbacks on 1932 // First, verify that adding valid extensions does invoke the callbacks on
1786 // the delegate. 1933 // the delegate.
1787 std::string id = id_util::GenerateId("foo"); 1934 std::string id = id_util::GenerateId("foo");
1788 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); 1935 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false));
1789 EXPECT_TRUE( 1936 EXPECT_TRUE(
1790 downloader->AddPendingExtension(id, GURL("http://example.com/update"), 1937 downloader->AddPendingExtension(id, GURL("http://example.com/update"),
1791 0)); 1938 0));
1792 downloader->StartAllPending(NULL); 1939 downloader->StartAllPending(NULL);
(...skipping 10 matching lines...) Expand all
1803 // Extensions with empty IDs should be rejected. 1950 // Extensions with empty IDs should be rejected.
1804 EXPECT_FALSE(downloader->AddPendingExtension(std::string(), GURL(), 0)); 1951 EXPECT_FALSE(downloader->AddPendingExtension(std::string(), GURL(), 0));
1805 downloader->StartAllPending(NULL); 1952 downloader->StartAllPending(NULL);
1806 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); 1953 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get()));
1807 1954
1808 // TODO(akalin): Test that extensions with empty update URLs 1955 // TODO(akalin): Test that extensions with empty update URLs
1809 // converted from user scripts are rejected. 1956 // converted from user scripts are rejected.
1810 1957
1811 // Reset the ExtensionDownloader so that it drops the current fetcher. 1958 // Reset the ExtensionDownloader so that it drops the current fetcher.
1812 downloader.reset( 1959 downloader.reset(
1813 new ExtensionDownloader(&delegate, service.request_context())); 1960 new ExtensionDownloader(&delegate, service.request_context(), NULL));
1814 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); 1961 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get()));
1815 1962
1816 // Extensions with empty update URLs should have a default one 1963 // Extensions with empty update URLs should have a default one
1817 // filled in. 1964 // filled in.
1818 id = id_util::GenerateId("foo3"); 1965 id = id_util::GenerateId("foo3");
1819 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); 1966 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false));
1820 EXPECT_TRUE(downloader->AddPendingExtension(id, GURL(), 0)); 1967 EXPECT_TRUE(downloader->AddPendingExtension(id, GURL(), 0));
1821 downloader->StartAllPending(NULL); 1968 downloader->StartAllPending(NULL);
1822 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); 1969 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get()));
1823 1970
1824 net::TestURLFetcher* fetcher = 1971 net::TestURLFetcher* fetcher =
1825 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 1972 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
1826 ASSERT_TRUE(fetcher); 1973 ASSERT_TRUE(fetcher);
1827 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); 1974 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty());
1828 } 1975 }
1829 1976
1830 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { 1977 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) {
1831 net::TestURLFetcherFactory factory; 1978 net::TestURLFetcherFactory factory;
1832 MockService service(prefs_.get()); 1979 MockService service(prefs_.get());
1833 MockExtensionDownloaderDelegate delegate; 1980 MockExtensionDownloaderDelegate delegate;
1834 ExtensionDownloader downloader(&delegate, service.request_context()); 1981 ExtensionDownloader downloader(&delegate, service.request_context(), NULL);
1835 1982
1836 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0)); 1983 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0));
1837 // This should delete the newly-created ManifestFetchData. 1984 // This should delete the newly-created ManifestFetchData.
1838 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0)); 1985 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0));
1839 // This should add into |manifests_pending_|. 1986 // This should add into |manifests_pending_|.
1840 StartUpdateCheck(&downloader, new ManifestFetchData(GURL( 1987 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(
1841 GURL("http://www.google.com")), 0)); 1988 GURL("http://www.google.com")), 0));
1842 // The dtor of |downloader| should delete the pending fetchers. 1989 // The dtor of |downloader| should delete the pending fetchers.
1843 } 1990 }
1844 1991
1845 TEST_F(ExtensionUpdaterTest, TestCheckSoon) { 1992 TEST_F(ExtensionUpdaterTest, TestCheckSoon) {
1846 ServiceForManifestTests service(prefs_.get()); 1993 ServiceForManifestTests service(prefs_.get());
1847 net::TestURLFetcherFactory factory; 1994 net::TestURLFetcherFactory factory;
1848 ExtensionUpdater updater( 1995 ExtensionUpdater updater(&service,
1849 &service, service.extension_prefs(), service.pref_service(), 1996 service.extension_prefs(),
1850 service.profile(), kUpdateFrequencySecs, NULL); 1997 service.pref_service(),
1998 service.profile(),
1999 kUpdateFrequencySecs,
2000 NULL,
2001 make_scoped_ptr<IdentityProvider>(NULL));
1851 EXPECT_FALSE(updater.WillCheckSoon()); 2002 EXPECT_FALSE(updater.WillCheckSoon());
1852 updater.Start(); 2003 updater.Start();
1853 EXPECT_FALSE(updater.WillCheckSoon()); 2004 EXPECT_FALSE(updater.WillCheckSoon());
1854 updater.CheckSoon(); 2005 updater.CheckSoon();
1855 EXPECT_TRUE(updater.WillCheckSoon()); 2006 EXPECT_TRUE(updater.WillCheckSoon());
1856 updater.CheckSoon(); 2007 updater.CheckSoon();
1857 EXPECT_TRUE(updater.WillCheckSoon()); 2008 EXPECT_TRUE(updater.WillCheckSoon());
1858 RunUntilIdle(); 2009 RunUntilIdle();
1859 EXPECT_FALSE(updater.WillCheckSoon()); 2010 EXPECT_FALSE(updater.WillCheckSoon());
1860 updater.CheckSoon(); 2011 updater.CheckSoon();
1861 EXPECT_TRUE(updater.WillCheckSoon()); 2012 EXPECT_TRUE(updater.WillCheckSoon());
1862 updater.Stop(); 2013 updater.Stop();
1863 EXPECT_FALSE(updater.WillCheckSoon()); 2014 EXPECT_FALSE(updater.WillCheckSoon());
1864 } 2015 }
1865 2016
1866 // TODO(asargent) - (http://crbug.com/12780) add tests for: 2017 // TODO(asargent) - (http://crbug.com/12780) add tests for:
1867 // -prodversionmin (shouldn't update if browser version too old) 2018 // -prodversionmin (shouldn't update if browser version too old)
1868 // -manifests & updates arriving out of order / interleaved 2019 // -manifests & updates arriving out of order / interleaved
1869 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 2020 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
1870 // -An extension gets uninstalled while updates are in progress (so it doesn't 2021 // -An extension gets uninstalled while updates are in progress (so it doesn't
1871 // "come back from the dead") 2022 // "come back from the dead")
1872 // -An extension gets manually updated to v3 while we're downloading v2 (ie 2023 // -An extension gets manually updated to v3 while we're downloading v2 (ie
1873 // you don't get downgraded accidentally) 2024 // you don't get downgraded accidentally)
1874 // -An update manifest mentions multiple updates 2025 // -An update manifest mentions multiple updates
1875 2026
1876 } // namespace extensions 2027 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/extension_updater.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698