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

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

Issue 23591050: Delete the omahaproxy-backed extension blacklist and clear its entries from the (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix memory leak in blacklist test Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <list> 5 #include <list>
6 #include <map> 6 #include <map>
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/sequenced_task_runner.h" 18 #include "base/sequenced_task_runner.h"
19 #include "base/stl_util.h" 19 #include "base/stl_util.h"
20 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_split.h" 21 #include "base/strings/string_split.h"
22 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "base/threading/thread.h" 24 #include "base/threading/thread.h"
25 #include "base/version.h" 25 #include "base/version.h"
26 #include "chrome/browser/chrome_notification_types.h" 26 #include "chrome/browser/chrome_notification_types.h"
27 #include "chrome/browser/extensions/blacklist.h"
28 #include "chrome/browser/extensions/crx_installer.h" 27 #include "chrome/browser/extensions/crx_installer.h"
29 #include "chrome/browser/extensions/extension_error_reporter.h" 28 #include "chrome/browser/extensions/extension_error_reporter.h"
30 #include "chrome/browser/extensions/extension_sync_data.h" 29 #include "chrome/browser/extensions/extension_sync_data.h"
31 #include "chrome/browser/extensions/extension_system.h" 30 #include "chrome/browser/extensions/extension_system.h"
32 #include "chrome/browser/extensions/test_blacklist.h"
33 #include "chrome/browser/extensions/test_extension_prefs.h" 31 #include "chrome/browser/extensions/test_extension_prefs.h"
34 #include "chrome/browser/extensions/test_extension_service.h" 32 #include "chrome/browser/extensions/test_extension_service.h"
35 #include "chrome/browser/extensions/test_extension_system.h" 33 #include "chrome/browser/extensions/test_extension_system.h"
36 #include "chrome/browser/extensions/updater/extension_downloader.h" 34 #include "chrome/browser/extensions/updater/extension_downloader.h"
37 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h" 35 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h"
38 #include "chrome/browser/extensions/updater/extension_updater.h" 36 #include "chrome/browser/extensions/updater/extension_updater.h"
39 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" 37 #include "chrome/browser/extensions/updater/manifest_fetch_data.h"
40 #include "chrome/browser/extensions/updater/request_queue_impl.h" 38 #include "chrome/browser/extensions/updater/request_queue_impl.h"
41 #include "chrome/browser/google/google_util.h" 39 #include "chrome/browser/google/google_util.h"
42 #include "chrome/browser/prefs/pref_service_syncable.h" 40 #include "chrome/browser/prefs/pref_service_syncable.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 MOCK_METHOD4(OnExtensionDownloadFailed, void(const std::string&, 125 MOCK_METHOD4(OnExtensionDownloadFailed, void(const std::string&,
128 Error, 126 Error,
129 const PingResult&, 127 const PingResult&,
130 const std::set<int>&)); 128 const std::set<int>&));
131 MOCK_METHOD6(OnExtensionDownloadFinished, void(const std::string&, 129 MOCK_METHOD6(OnExtensionDownloadFinished, void(const std::string&,
132 const base::FilePath&, 130 const base::FilePath&,
133 const GURL&, 131 const GURL&,
134 const std::string&, 132 const std::string&,
135 const PingResult&, 133 const PingResult&,
136 const std::set<int>&)); 134 const std::set<int>&));
137 MOCK_METHOD5(OnBlacklistDownloadFinished, void(const std::string&,
138 const std::string&,
139 const std::string&,
140 const PingResult&,
141 const std::set<int>&));
142 MOCK_METHOD2(GetPingDataForExtension, 135 MOCK_METHOD2(GetPingDataForExtension,
143 bool(const std::string&, ManifestFetchData::PingData*)); 136 bool(const std::string&, ManifestFetchData::PingData*));
144 MOCK_METHOD1(GetUpdateUrlData, std::string(const std::string&)); 137 MOCK_METHOD1(GetUpdateUrlData, std::string(const std::string&));
145 MOCK_METHOD1(IsExtensionPending, bool(const std::string&)); 138 MOCK_METHOD1(IsExtensionPending, bool(const std::string&));
146 MOCK_METHOD2(GetExtensionExistingVersion, 139 MOCK_METHOD2(GetExtensionExistingVersion,
147 bool(const std::string&, std::string*)); 140 bool(const std::string&, std::string*));
148 141
149 void Wait() { 142 void Wait() {
150 scoped_refptr<content::MessageLoopRunner> runner = 143 scoped_refptr<content::MessageLoopRunner> runner =
151 new content::MessageLoopRunner; 144 new content::MessageLoopRunner;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 222
230 DISALLOW_COPY_AND_ASSIGN(NotificationsObserver); 223 DISALLOW_COPY_AND_ASSIGN(NotificationsObserver);
231 }; 224 };
232 225
233 } // namespace 226 } // namespace
234 227
235 // Base class for further specialized test classes. 228 // Base class for further specialized test classes.
236 class MockService : public TestExtensionService { 229 class MockService : public TestExtensionService {
237 public: 230 public:
238 explicit MockService(TestExtensionPrefs* prefs) 231 explicit MockService(TestExtensionPrefs* prefs)
239 : prefs_(prefs), 232 : prefs_(prefs), pending_extension_manager_(*this) {
240 pending_extension_manager_(*this),
241 blacklist_(prefs_->prefs()) {
242 } 233 }
243 234
244 virtual ~MockService() {} 235 virtual ~MockService() {}
245 236
246 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE { 237 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE {
247 ADD_FAILURE() << "Subclass should override this if it will " 238 ADD_FAILURE() << "Subclass should override this if it will "
248 << "be accessed by a test."; 239 << "be accessed by a test.";
249 return &pending_extension_manager_; 240 return &pending_extension_manager_;
250 } 241 }
251 242
252 Profile* profile() { return &profile_; } 243 Profile* profile() { return &profile_; }
253 244
254 net::URLRequestContextGetter* request_context() { 245 net::URLRequestContextGetter* request_context() {
255 return profile_.GetRequestContext(); 246 return profile_.GetRequestContext();
256 } 247 }
257 248
258 ExtensionPrefs* extension_prefs() { return prefs_->prefs(); } 249 ExtensionPrefs* extension_prefs() { return prefs_->prefs(); }
259 250
260 PrefService* pref_service() { return prefs_->pref_service(); } 251 PrefService* pref_service() { return prefs_->pref_service(); }
261 252
262 Blacklist* blacklist() { return &blacklist_; }
263
264 // Creates test extensions and inserts them into list. The name and 253 // Creates test extensions and inserts them into list. The name and
265 // version are all based on their index. If |update_url| is non-null, it 254 // version are all based on their index. If |update_url| is non-null, it
266 // will be used as the update_url for each extension. 255 // will be used as the update_url for each extension.
267 // The |id| is used to distinguish extension names and make sure that 256 // The |id| is used to distinguish extension names and make sure that
268 // no two extensions share the same name. 257 // no two extensions share the same name.
269 void CreateTestExtensions(int id, int count, ExtensionList *list, 258 void CreateTestExtensions(int id, int count, ExtensionList *list,
270 const std::string* update_url, 259 const std::string* update_url,
271 Manifest::Location location) { 260 Manifest::Location location) {
272 for (int i = 1; i <= count; i++) { 261 for (int i = 1; i <= count; i++) {
273 DictionaryValue manifest; 262 DictionaryValue manifest;
274 manifest.SetString(manifest_keys::kVersion, 263 manifest.SetString(manifest_keys::kVersion,
275 base::StringPrintf("%d.0.0.0", i)); 264 base::StringPrintf("%d.0.0.0", i));
276 manifest.SetString(manifest_keys::kName, 265 manifest.SetString(manifest_keys::kName,
277 base::StringPrintf("Extension %d.%d", id, i)); 266 base::StringPrintf("Extension %d.%d", id, i));
278 if (update_url) 267 if (update_url)
279 manifest.SetString(manifest_keys::kUpdateURL, *update_url); 268 manifest.SetString(manifest_keys::kUpdateURL, *update_url);
280 scoped_refptr<Extension> e = 269 scoped_refptr<Extension> e =
281 prefs_->AddExtensionWithManifest(manifest, location); 270 prefs_->AddExtensionWithManifest(manifest, location);
282 ASSERT_TRUE(e.get() != NULL); 271 ASSERT_TRUE(e.get() != NULL);
283 list->push_back(e); 272 list->push_back(e);
284 } 273 }
285 } 274 }
286 275
287 protected: 276 protected:
288 TestExtensionPrefs* const prefs_; 277 TestExtensionPrefs* const prefs_;
289 PendingExtensionManager pending_extension_manager_; 278 PendingExtensionManager pending_extension_manager_;
290 TestingProfile profile_; 279 TestingProfile profile_;
291 Blacklist blacklist_;
292 280
293 private: 281 private:
294 DISALLOW_COPY_AND_ASSIGN(MockService); 282 DISALLOW_COPY_AND_ASSIGN(MockService);
295 }; 283 };
296 284
297 285
298 bool ShouldInstallExtensionsOnly(const Extension* extension) { 286 bool ShouldInstallExtensionsOnly(const Extension* extension) {
299 return extension->GetType() == Manifest::TYPE_EXTENSION; 287 return extension->GetType() == Manifest::TYPE_EXTENSION;
300 } 288 }
301 289
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 } else { 556 } else {
569 service.CreateTestExtensions(1, 1, &extensions, &update_url, 557 service.CreateTestExtensions(1, 1, &extensions, &update_url,
570 Manifest::INTERNAL); 558 Manifest::INTERNAL);
571 service.set_extensions(extensions); 559 service.set_extensions(extensions);
572 } 560 }
573 561
574 // Set up and start the updater. 562 // Set up and start the updater.
575 net::TestURLFetcherFactory factory; 563 net::TestURLFetcherFactory factory;
576 ExtensionUpdater updater( 564 ExtensionUpdater updater(
577 &service, service.extension_prefs(), service.pref_service(), 565 &service, service.extension_prefs(), service.pref_service(),
578 service.profile(), service.blacklist(), 60*60*24); 566 service.profile(), 60*60*24);
579 updater.Start(); 567 updater.Start();
580 // Disable blacklist checks (tested elsewhere) so that we only see the
581 // update HTTP request.
582 ExtensionUpdater::CheckParams check_params;
583 check_params.check_blacklist = false;
584 updater.set_default_check_params(check_params);
585 568
586 // Tell the update that it's time to do update checks. 569 // Tell the update that it's time to do update checks.
587 EXPECT_EQ(0u, observer.StartedCount()); 570 EXPECT_EQ(0u, observer.StartedCount());
588 SimulateTimerFired(&updater); 571 SimulateTimerFired(&updater);
589 EXPECT_EQ(1u, observer.StartedCount()); 572 EXPECT_EQ(1u, observer.StartedCount());
590 573
591 // Get the url our mock fetcher was asked to fetch. 574 // Get the url our mock fetcher was asked to fetch.
592 net::TestURLFetcher* fetcher = 575 net::TestURLFetcher* fetcher =
593 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 576 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
594 const GURL& url = fetcher->GetOriginalURL(); 577 const GURL& url = fetcher->GetOriginalURL();
(...skipping 11 matching lines...) Expand all
606 if (pending) { 589 if (pending) {
607 EXPECT_TRUE(pending_extension_manager->IsIdPending(params["id"])); 590 EXPECT_TRUE(pending_extension_manager->IsIdPending(params["id"]));
608 EXPECT_EQ("0.0.0.0", params["v"]); 591 EXPECT_EQ("0.0.0.0", params["v"]);
609 } else { 592 } else {
610 EXPECT_EQ(extensions[0]->id(), params["id"]); 593 EXPECT_EQ(extensions[0]->id(), params["id"]);
611 EXPECT_EQ(extensions[0]->VersionString(), params["v"]); 594 EXPECT_EQ(extensions[0]->VersionString(), params["v"]);
612 } 595 }
613 EXPECT_EQ("", params["uc"]); 596 EXPECT_EQ("", params["uc"]);
614 } 597 }
615 598
616 void TestBlacklistUpdateCheckRequests() {
617 // Setup and start the updater.
618 ServiceForManifestTests service(prefs_.get());
619 NotificationsObserver observer;
620
621 net::TestURLFetcherFactory factory;
622 ExtensionUpdater updater(
623 &service, service.extension_prefs(), service.pref_service(),
624 service.profile(), service.blacklist(), 60*60*24);
625 updater.Start();
626
627 // Tell the updater that it's time to do update checks.
628 EXPECT_EQ(0u, observer.StartedCount());
629 SimulateTimerFired(&updater);
630 EXPECT_EQ(1u, observer.StartedCount());
631
632 // Get the url our mock fetcher was asked to fetch.
633 net::TestURLFetcher* fetcher =
634 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
635 ASSERT_FALSE(fetcher == NULL);
636 const GURL& url = fetcher->GetOriginalURL();
637
638 EXPECT_FALSE(url.is_empty());
639 EXPECT_TRUE(url.is_valid());
640 EXPECT_TRUE(url.SchemeIs("https"));
641 EXPECT_EQ("clients2.google.com", url.host());
642 EXPECT_EQ("/service/update2/crx", url.path());
643
644 // Validate the extension request parameters in the query. It should
645 // look something like "x=id%3D<id>%26v%3D<version>%26uc".
646 EXPECT_TRUE(url.has_query());
647 std::map<std::string, std::string> params;
648 VerifyQueryAndExtractParameters(url.query(), &params);
649 EXPECT_EQ("com.google.crx.blacklist", params["id"]);
650 EXPECT_EQ("0", params["v"]);
651 EXPECT_EQ("", params["uc"]);
652 EXPECT_TRUE(ContainsKey(params, "ping"));
653 }
654
655 void TestUpdateUrlDataEmpty() { 599 void TestUpdateUrlDataEmpty() {
656 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 600 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
657 const std::string version = "1.0"; 601 const std::string version = "1.0";
658 602
659 // Make sure that an empty update URL data string does not cause a ap= 603 // Make sure that an empty update URL data string does not cause a ap=
660 // option to appear in the x= parameter. 604 // option to appear in the x= parameter.
661 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 605 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
662 fetch_data.AddExtension( 606 fetch_data.AddExtension(
663 id, version, &kNeverPingedData, std::string(), std::string()); 607 id, version, &kNeverPingedData, std::string(), std::string());
664 608
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 } 965 }
1022 966
1023 void TestSingleExtensionDownloading(bool pending, bool retry) { 967 void TestSingleExtensionDownloading(bool pending, bool retry) {
1024 net::TestURLFetcherFactory factory; 968 net::TestURLFetcherFactory factory;
1025 net::TestURLFetcher* fetcher = NULL; 969 net::TestURLFetcher* fetcher = NULL;
1026 scoped_ptr<ServiceForDownloadTests> service( 970 scoped_ptr<ServiceForDownloadTests> service(
1027 new ServiceForDownloadTests(prefs_.get())); 971 new ServiceForDownloadTests(prefs_.get()));
1028 ExtensionUpdater updater(service.get(), service->extension_prefs(), 972 ExtensionUpdater updater(service.get(), service->extension_prefs(),
1029 service->pref_service(), 973 service->pref_service(),
1030 service->profile(), 974 service->profile(),
1031 service->blacklist(),
1032 kUpdateFrequencySecs); 975 kUpdateFrequencySecs);
1033 updater.Start(); 976 updater.Start();
1034 ResetDownloader( 977 ResetDownloader(
1035 &updater, 978 &updater,
1036 new ExtensionDownloader(&updater, service->request_context())); 979 new ExtensionDownloader(&updater, service->request_context()));
1037 updater.downloader_->extensions_queue_.set_backoff_policy( 980 updater.downloader_->extensions_queue_.set_backoff_policy(
1038 &kNoBackoffPolicy); 981 &kNoBackoffPolicy);
1039 982
1040 GURL test_url("http://localhost/extension.crx"); 983 GURL test_url("http://localhost/extension.crx");
1041 984
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 1034
1092 // Expect that ExtensionUpdater asked the mock extensions service to install 1035 // Expect that ExtensionUpdater asked the mock extensions service to install
1093 // a file with the test data for the right id. 1036 // a file with the test data for the right id.
1094 EXPECT_EQ(id, service->extension_id()); 1037 EXPECT_EQ(id, service->extension_id());
1095 base::FilePath tmpfile_path = service->install_path(); 1038 base::FilePath tmpfile_path = service->install_path();
1096 EXPECT_FALSE(tmpfile_path.empty()); 1039 EXPECT_FALSE(tmpfile_path.empty());
1097 EXPECT_EQ(test_url, service->download_url()); 1040 EXPECT_EQ(test_url, service->download_url());
1098 EXPECT_EQ(extension_file_path, tmpfile_path); 1041 EXPECT_EQ(extension_file_path, tmpfile_path);
1099 } 1042 }
1100 1043
1101 void TestBlacklistDownloading() {
1102 net::TestURLFetcherFactory factory;
1103 net::TestURLFetcher* fetcher = NULL;
1104 MockService service(prefs_.get());
1105 TestBlacklist blacklist(service.blacklist());
1106 ExtensionUpdater updater(
1107 &service, service.extension_prefs(), service.pref_service(),
1108 service.profile(), blacklist.blacklist(), kUpdateFrequencySecs);
1109 updater.Start();
1110 ResetDownloader(
1111 &updater,
1112 new ExtensionDownloader(&updater, service.request_context()));
1113 updater.downloader_->extensions_queue_.set_backoff_policy(
1114 &kNoBackoffPolicy);
1115
1116 GURL test_url("http://localhost/extension.crx");
1117
1118 std::string id = "com.google.crx.blacklist";
1119
1120 std::string hash =
1121 "CCEA231D3CD30A348DA1383ED311EAC11E82360773CB2BA4E2C3A5FF16E337CC";
1122
1123 std::string version = "0.0.1";
1124 std::set<int> requests;
1125 requests.insert(0);
1126 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch(
1127 new ExtensionDownloader::ExtensionFetch(
1128 id, test_url, hash, version, requests));
1129 updater.downloader_->FetchUpdatedExtension(fetch.Pass());
1130
1131 // Call back the ExtensionUpdater with a 200 response and some test data.
1132 std::string extension_data("aaaabbbbcccceeeeaaaabbbbcccceeee");
1133 EXPECT_FALSE(blacklist.IsBlacklisted(extension_data));
1134
1135 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId);
1136 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
1137 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags);
1138
1139 fetcher->set_url(test_url);
1140 fetcher->set_status(net::URLRequestStatus());
1141 fetcher->set_response_code(200);
1142 fetcher->SetResponseString(extension_data);
1143 fetcher->delegate()->OnURLFetchComplete(fetcher);
1144
1145 RunUntilIdle();
1146
1147 EXPECT_TRUE(blacklist.IsBlacklisted(extension_data));
1148
1149 EXPECT_EQ(version, service.pref_service()->
1150 GetString(prefs::kExtensionBlacklistUpdateVersion));
1151 }
1152
1153 // Two extensions are updated. If |updates_start_running| is true, the 1044 // Two extensions are updated. If |updates_start_running| is true, the
1154 // mock extensions service has UpdateExtension(...) return true, and 1045 // mock extensions service has UpdateExtension(...) return true, and
1155 // the test is responsible for creating fake CrxInstallers. Otherwise, 1046 // the test is responsible for creating fake CrxInstallers. Otherwise,
1156 // UpdateExtension() returns false, signaling install failures. 1047 // UpdateExtension() returns false, signaling install failures.
1157 void TestMultipleExtensionDownloading(bool updates_start_running) { 1048 void TestMultipleExtensionDownloading(bool updates_start_running) {
1158 net::TestURLFetcherFactory factory; 1049 net::TestURLFetcherFactory factory;
1159 net::TestURLFetcher* fetcher = NULL; 1050 net::TestURLFetcher* fetcher = NULL;
1160 ServiceForDownloadTests service(prefs_.get()); 1051 ServiceForDownloadTests service(prefs_.get());
1161 ExtensionUpdater updater( 1052 ExtensionUpdater updater(
1162 &service, service.extension_prefs(), service.pref_service(), 1053 &service, service.extension_prefs(), service.pref_service(),
1163 service.profile(), service.blacklist(), kUpdateFrequencySecs); 1054 service.profile(), kUpdateFrequencySecs);
1164 updater.Start(); 1055 updater.Start();
1165 ResetDownloader( 1056 ResetDownloader(
1166 &updater, 1057 &updater,
1167 new ExtensionDownloader(&updater, service.request_context())); 1058 new ExtensionDownloader(&updater, service.request_context()));
1168 updater.downloader_->extensions_queue_.set_backoff_policy( 1059 updater.downloader_->extensions_queue_.set_backoff_policy(
1169 &kNoBackoffPolicy); 1060 &kNoBackoffPolicy);
1170 1061
1171 EXPECT_FALSE(updater.crx_install_is_running_); 1062 EXPECT_FALSE(updater.crx_install_is_running_);
1172 1063
1173 GURL url1("http://localhost/extension1.crx"); 1064 GURL url1("http://localhost/extension1.crx");
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 Time last_active_ping_day = now - 1258 Time last_active_ping_day = now -
1368 TimeDelta::FromDays(active_ping_days) - 1259 TimeDelta::FromDays(active_ping_days) -
1369 TimeDelta::FromSeconds(15); 1260 TimeDelta::FromSeconds(15);
1370 prefs->SetLastActivePingDay(id, last_active_ping_day); 1261 prefs->SetLastActivePingDay(id, last_active_ping_day);
1371 } 1262 }
1372 if (active_bit) 1263 if (active_bit)
1373 prefs->SetActiveBit(id, true); 1264 prefs->SetActiveBit(id, true);
1374 1265
1375 ExtensionUpdater updater( 1266 ExtensionUpdater updater(
1376 &service, service.extension_prefs(), service.pref_service(), 1267 &service, service.extension_prefs(), service.pref_service(),
1377 service.profile(), service.blacklist(), kUpdateFrequencySecs); 1268 service.profile(), kUpdateFrequencySecs);
1378 ExtensionUpdater::CheckParams params; 1269 ExtensionUpdater::CheckParams params;
1379 params.check_blacklist = false;
1380 updater.Start(); 1270 updater.Start();
1381 updater.CheckNow(params); 1271 updater.CheckNow(params);
1382 1272
1383 // Make the updater do manifest fetching, and note the urls it tries to 1273 // Make the updater do manifest fetching, and note the urls it tries to
1384 // fetch. 1274 // fetch.
1385 std::vector<GURL> fetched_urls; 1275 std::vector<GURL> fetched_urls;
1386 net::TestURLFetcher* fetcher = 1276 net::TestURLFetcher* fetcher =
1387 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 1277 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
1388 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 1278 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
1389 fetched_urls.push_back(fetcher->GetOriginalURL()); 1279 fetched_urls.push_back(fetcher->GetOriginalURL());
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 void TestHandleManifestResults() { 1351 void TestHandleManifestResults() {
1462 ServiceForManifestTests service(prefs_.get()); 1352 ServiceForManifestTests service(prefs_.get());
1463 GURL update_url("http://www.google.com/manifest"); 1353 GURL update_url("http://www.google.com/manifest");
1464 ExtensionList tmp; 1354 ExtensionList tmp;
1465 service.CreateTestExtensions(1, 1, &tmp, &update_url.spec(), 1355 service.CreateTestExtensions(1, 1, &tmp, &update_url.spec(),
1466 Manifest::INTERNAL); 1356 Manifest::INTERNAL);
1467 service.set_extensions(tmp); 1357 service.set_extensions(tmp);
1468 1358
1469 ExtensionUpdater updater( 1359 ExtensionUpdater updater(
1470 &service, service.extension_prefs(), service.pref_service(), 1360 &service, service.extension_prefs(), service.pref_service(),
1471 service.profile(), service.blacklist(), kUpdateFrequencySecs); 1361 service.profile(), kUpdateFrequencySecs);
1472 updater.Start(); 1362 updater.Start();
1473 ResetDownloader( 1363 ResetDownloader(
1474 &updater, 1364 &updater,
1475 new ExtensionDownloader(&updater, service.request_context())); 1365 new ExtensionDownloader(&updater, service.request_context()));
1476 1366
1477 ManifestFetchData fetch_data(update_url, 0); 1367 ManifestFetchData fetch_data(update_url, 0);
1478 const Extension* extension = tmp[0].get(); 1368 const Extension* extension = tmp[0].get();
1479 fetch_data.AddExtension(extension->id(), 1369 fetch_data.AddExtension(extension->id(),
1480 extension->VersionString(), 1370 extension->VersionString(),
1481 &kNeverPingedData, 1371 &kNeverPingedData,
(...skipping 28 matching lines...) Expand all
1510 // subclasses where friendship with ExtenionUpdater is not inherited. 1400 // subclasses where friendship with ExtenionUpdater is not inherited.
1511 1401
1512 TEST_F(ExtensionUpdaterTest, TestExtensionUpdateCheckRequests) { 1402 TEST_F(ExtensionUpdaterTest, TestExtensionUpdateCheckRequests) {
1513 TestExtensionUpdateCheckRequests(false); 1403 TestExtensionUpdateCheckRequests(false);
1514 } 1404 }
1515 1405
1516 TEST_F(ExtensionUpdaterTest, TestExtensionUpdateCheckRequestsPending) { 1406 TEST_F(ExtensionUpdaterTest, TestExtensionUpdateCheckRequestsPending) {
1517 TestExtensionUpdateCheckRequests(true); 1407 TestExtensionUpdateCheckRequests(true);
1518 } 1408 }
1519 1409
1520 TEST_F(ExtensionUpdaterTest, TestBlacklistUpdateCheckRequests) {
1521 TestBlacklistUpdateCheckRequests();
1522 }
1523
1524 TEST_F(ExtensionUpdaterTest, TestUpdateUrlData) { 1410 TEST_F(ExtensionUpdaterTest, TestUpdateUrlData) {
1525 TestUpdateUrlDataEmpty(); 1411 TestUpdateUrlDataEmpty();
1526 TestUpdateUrlDataSimple(); 1412 TestUpdateUrlDataSimple();
1527 TestUpdateUrlDataCompound(); 1413 TestUpdateUrlDataCompound();
1528 TestUpdateUrlDataFromGallery( 1414 TestUpdateUrlDataFromGallery(
1529 extension_urls::GetWebstoreUpdateUrl().spec()); 1415 extension_urls::GetWebstoreUpdateUrl().spec());
1530 } 1416 }
1531 1417
1532 TEST_F(ExtensionUpdaterTest, TestInstallSource) { 1418 TEST_F(ExtensionUpdaterTest, TestInstallSource) {
1533 TestInstallSource(); 1419 TestInstallSource();
(...skipping 20 matching lines...) Expand all
1554 } 1440 }
1555 1441
1556 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingWithRetry) { 1442 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingWithRetry) {
1557 TestSingleExtensionDownloading(false, true); 1443 TestSingleExtensionDownloading(false, true);
1558 } 1444 }
1559 1445
1560 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingPendingWithRetry) { 1446 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingPendingWithRetry) {
1561 TestSingleExtensionDownloading(true, true); 1447 TestSingleExtensionDownloading(true, true);
1562 } 1448 }
1563 1449
1564 TEST_F(ExtensionUpdaterTest, TestBlacklistDownloading) {
1565 TestBlacklistDownloading();
1566 }
1567
1568 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) { 1450 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) {
1569 TestMultipleExtensionDownloading(false); 1451 TestMultipleExtensionDownloading(false);
1570 } 1452 }
1571 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesSucceed) { 1453 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesSucceed) {
1572 TestMultipleExtensionDownloading(true); 1454 TestMultipleExtensionDownloading(true);
1573 } 1455 }
1574 1456
1575 TEST_F(ExtensionUpdaterTest, TestManifestRetryDownloading) { 1457 TEST_F(ExtensionUpdaterTest, TestManifestRetryDownloading) {
1576 TestManifestRetryDownloading(); 1458 TestManifestRetryDownloading();
1577 } 1459 }
1578 1460
1579 TEST_F(ExtensionUpdaterTest, TestGalleryRequestsWithOrganicBrand) { 1461 TEST_F(ExtensionUpdaterTest, TestGalleryRequestsWithOrganicBrand) {
1580 TestGalleryRequestsWithBrand(true); 1462 TestGalleryRequestsWithBrand(true);
1581 } 1463 }
1582 1464
1583 TEST_F(ExtensionUpdaterTest, TestGalleryRequestsWithNonOrganicBrand) { 1465 TEST_F(ExtensionUpdaterTest, TestGalleryRequestsWithNonOrganicBrand) {
1584 TestGalleryRequestsWithBrand(false); 1466 TestGalleryRequestsWithBrand(false);
1585 } 1467 }
1586 1468
1587 TEST_F(ExtensionUpdaterTest, TestHandleManifestResults) { 1469 TEST_F(ExtensionUpdaterTest, TestHandleManifestResults) {
1588 TestHandleManifestResults(); 1470 TestHandleManifestResults();
1589 } 1471 }
1590 1472
1591 TEST_F(ExtensionUpdaterTest, TestNonAutoUpdateableLocations) { 1473 TEST_F(ExtensionUpdaterTest, TestNonAutoUpdateableLocations) {
1592 net::TestURLFetcherFactory factory; 1474 net::TestURLFetcherFactory factory;
1593 ServiceForManifestTests service(prefs_.get()); 1475 ServiceForManifestTests service(prefs_.get());
1594 ExtensionUpdater updater(&service, service.extension_prefs(), 1476 ExtensionUpdater updater(&service, service.extension_prefs(),
1595 service.pref_service(), service.profile(), 1477 service.pref_service(), service.profile(),
1596 service.blacklist(), kUpdateFrequencySecs); 1478 kUpdateFrequencySecs);
1597 MockExtensionDownloaderDelegate delegate; 1479 MockExtensionDownloaderDelegate delegate;
1598 // Set the downloader directly, so that all its events end up in the mock 1480 // Set the downloader directly, so that all its events end up in the mock
1599 // |delegate|. 1481 // |delegate|.
1600 ExtensionDownloader* downloader = 1482 ExtensionDownloader* downloader =
1601 new ExtensionDownloader(&delegate, service.request_context()); 1483 new ExtensionDownloader(&delegate, service.request_context());
1602 ResetDownloader(&updater, downloader); 1484 ResetDownloader(&updater, downloader);
1603 1485
1604 // Non-internal non-external extensions should be rejected. 1486 // Non-internal non-external extensions should be rejected.
1605 ExtensionList extensions; 1487 ExtensionList extensions;
1606 service.CreateTestExtensions(1, 1, &extensions, NULL, 1488 service.CreateTestExtensions(1, 1, &extensions, NULL,
1607 Manifest::INVALID_LOCATION); 1489 Manifest::INVALID_LOCATION);
1608 service.CreateTestExtensions(2, 1, &extensions, NULL, Manifest::INTERNAL); 1490 service.CreateTestExtensions(2, 1, &extensions, NULL, Manifest::INTERNAL);
1609 ASSERT_EQ(2u, extensions.size()); 1491 ASSERT_EQ(2u, extensions.size());
1610 const std::string& updateable_id = extensions[1]->id(); 1492 const std::string& updateable_id = extensions[1]->id();
1611 1493
1612 // These expectations fail if the delegate's methods are invoked for the 1494 // These expectations fail if the delegate's methods are invoked for the
1613 // first extension, which has a non-matching id. 1495 // first extension, which has a non-matching id.
1614 EXPECT_CALL(delegate, GetUpdateUrlData(updateable_id)).WillOnce(Return("")); 1496 EXPECT_CALL(delegate, GetUpdateUrlData(updateable_id)).WillOnce(Return(""));
1615 EXPECT_CALL(delegate, GetPingDataForExtension(updateable_id, _)); 1497 EXPECT_CALL(delegate, GetPingDataForExtension(updateable_id, _));
1616 1498
1617 service.set_extensions(extensions); 1499 service.set_extensions(extensions);
1618 ExtensionUpdater::CheckParams params; 1500 ExtensionUpdater::CheckParams params;
1619 params.check_blacklist = false;
1620 updater.Start(); 1501 updater.Start();
1621 updater.CheckNow(params); 1502 updater.CheckNow(params);
1622 } 1503 }
1623 1504
1624 TEST_F(ExtensionUpdaterTest, TestUpdatingDisabledExtensions) { 1505 TEST_F(ExtensionUpdaterTest, TestUpdatingDisabledExtensions) {
1625 net::TestURLFetcherFactory factory; 1506 net::TestURLFetcherFactory factory;
1626 ServiceForManifestTests service(prefs_.get()); 1507 ServiceForManifestTests service(prefs_.get());
1627 ExtensionUpdater updater(&service, service.extension_prefs(), 1508 ExtensionUpdater updater(&service, service.extension_prefs(),
1628 service.pref_service(), service.profile(), 1509 service.pref_service(), service.profile(),
1629 service.blacklist(), kUpdateFrequencySecs); 1510 kUpdateFrequencySecs);
1630 MockExtensionDownloaderDelegate delegate; 1511 MockExtensionDownloaderDelegate delegate;
1631 // Set the downloader directly, so that all its events end up in the mock 1512 // Set the downloader directly, so that all its events end up in the mock
1632 // |delegate|. 1513 // |delegate|.
1633 ExtensionDownloader* downloader = 1514 ExtensionDownloader* downloader =
1634 new ExtensionDownloader(&delegate, service.request_context()); 1515 new ExtensionDownloader(&delegate, service.request_context());
1635 ResetDownloader(&updater, downloader); 1516 ResetDownloader(&updater, downloader);
1636 1517
1637 // Non-internal non-external extensions should be rejected. 1518 // Non-internal non-external extensions should be rejected.
1638 ExtensionList enabled_extensions; 1519 ExtensionList enabled_extensions;
1639 ExtensionList disabled_extensions; 1520 ExtensionList disabled_extensions;
1640 service.CreateTestExtensions(1, 1, &enabled_extensions, NULL, 1521 service.CreateTestExtensions(1, 1, &enabled_extensions, NULL,
1641 Manifest::INTERNAL); 1522 Manifest::INTERNAL);
1642 service.CreateTestExtensions(2, 1, &disabled_extensions, NULL, 1523 service.CreateTestExtensions(2, 1, &disabled_extensions, NULL,
1643 Manifest::INTERNAL); 1524 Manifest::INTERNAL);
1644 ASSERT_EQ(1u, enabled_extensions.size()); 1525 ASSERT_EQ(1u, enabled_extensions.size());
1645 ASSERT_EQ(1u, disabled_extensions.size()); 1526 ASSERT_EQ(1u, disabled_extensions.size());
1646 const std::string& enabled_id = enabled_extensions[0]->id(); 1527 const std::string& enabled_id = enabled_extensions[0]->id();
1647 const std::string& disabled_id = disabled_extensions[0]->id(); 1528 const std::string& disabled_id = disabled_extensions[0]->id();
1648 1529
1649 // We expect that both enabled and disabled extensions are auto-updated. 1530 // We expect that both enabled and disabled extensions are auto-updated.
1650 EXPECT_CALL(delegate, GetUpdateUrlData(enabled_id)).WillOnce(Return("")); 1531 EXPECT_CALL(delegate, GetUpdateUrlData(enabled_id)).WillOnce(Return(""));
1651 EXPECT_CALL(delegate, GetPingDataForExtension(enabled_id, _)); 1532 EXPECT_CALL(delegate, GetPingDataForExtension(enabled_id, _));
1652 EXPECT_CALL(delegate, GetUpdateUrlData(disabled_id)).WillOnce(Return("")); 1533 EXPECT_CALL(delegate, GetUpdateUrlData(disabled_id)).WillOnce(Return(""));
1653 EXPECT_CALL(delegate, GetPingDataForExtension(disabled_id, _)); 1534 EXPECT_CALL(delegate, GetPingDataForExtension(disabled_id, _));
1654 1535
1655 service.set_extensions(enabled_extensions); 1536 service.set_extensions(enabled_extensions);
1656 service.set_disabled_extensions(disabled_extensions); 1537 service.set_disabled_extensions(disabled_extensions);
1657 ExtensionUpdater::CheckParams params; 1538 ExtensionUpdater::CheckParams params;
1658 params.check_blacklist = false;
1659 updater.Start(); 1539 updater.Start();
1660 updater.CheckNow(params); 1540 updater.CheckNow(params);
1661 } 1541 }
1662 1542
1663 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { 1543 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) {
1664 net::TestURLFetcherFactory factory; 1544 net::TestURLFetcherFactory factory;
1665 MockService service(prefs_.get()); 1545 MockService service(prefs_.get());
1666 MockExtensionDownloaderDelegate delegate; 1546 MockExtensionDownloaderDelegate delegate;
1667 scoped_ptr<ExtensionDownloader> downloader( 1547 scoped_ptr<ExtensionDownloader> downloader(
1668 new ExtensionDownloader(&delegate, service.request_context())); 1548 new ExtensionDownloader(&delegate, service.request_context()));
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 StartUpdateCheck(&downloader, new ManifestFetchData(GURL( 1606 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(
1727 GURL("http://www.google.com")), 0)); 1607 GURL("http://www.google.com")), 0));
1728 // The dtor of |downloader| should delete the pending fetchers. 1608 // The dtor of |downloader| should delete the pending fetchers.
1729 } 1609 }
1730 1610
1731 TEST_F(ExtensionUpdaterTest, TestCheckSoon) { 1611 TEST_F(ExtensionUpdaterTest, TestCheckSoon) {
1732 ServiceForManifestTests service(prefs_.get()); 1612 ServiceForManifestTests service(prefs_.get());
1733 net::TestURLFetcherFactory factory; 1613 net::TestURLFetcherFactory factory;
1734 ExtensionUpdater updater( 1614 ExtensionUpdater updater(
1735 &service, service.extension_prefs(), service.pref_service(), 1615 &service, service.extension_prefs(), service.pref_service(),
1736 service.profile(), service.blacklist(), kUpdateFrequencySecs); 1616 service.profile(), kUpdateFrequencySecs);
1737 EXPECT_FALSE(updater.WillCheckSoon()); 1617 EXPECT_FALSE(updater.WillCheckSoon());
1738 updater.Start(); 1618 updater.Start();
1739 EXPECT_FALSE(updater.WillCheckSoon()); 1619 EXPECT_FALSE(updater.WillCheckSoon());
1740 updater.CheckSoon(); 1620 updater.CheckSoon();
1741 EXPECT_TRUE(updater.WillCheckSoon()); 1621 EXPECT_TRUE(updater.WillCheckSoon());
1742 updater.CheckSoon(); 1622 updater.CheckSoon();
1743 EXPECT_TRUE(updater.WillCheckSoon()); 1623 EXPECT_TRUE(updater.WillCheckSoon());
1744 RunUntilIdle(); 1624 RunUntilIdle();
1745 EXPECT_FALSE(updater.WillCheckSoon()); 1625 EXPECT_FALSE(updater.WillCheckSoon());
1746 updater.CheckSoon(); 1626 updater.CheckSoon();
1747 EXPECT_TRUE(updater.WillCheckSoon()); 1627 EXPECT_TRUE(updater.WillCheckSoon());
1748 updater.Stop(); 1628 updater.Stop();
1749 EXPECT_FALSE(updater.WillCheckSoon()); 1629 EXPECT_FALSE(updater.WillCheckSoon());
1750 } 1630 }
1751 1631
1752 // TODO(asargent) - (http://crbug.com/12780) add tests for: 1632 // TODO(asargent) - (http://crbug.com/12780) add tests for:
1753 // -prodversionmin (shouldn't update if browser version too old) 1633 // -prodversionmin (shouldn't update if browser version too old)
1754 // -manifests & updates arriving out of order / interleaved 1634 // -manifests & updates arriving out of order / interleaved
1755 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 1635 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
1756 // -An extension gets uninstalled while updates are in progress (so it doesn't 1636 // -An extension gets uninstalled while updates are in progress (so it doesn't
1757 // "come back from the dead") 1637 // "come back from the dead")
1758 // -An extension gets manually updated to v3 while we're downloading v2 (ie 1638 // -An extension gets manually updated to v3 while we're downloading v2 (ie
1759 // you don't get downgraded accidentally) 1639 // you don't get downgraded accidentally)
1760 // -An update manifest mentions multiple updates 1640 // -An update manifest mentions multiple updates
1761 1641
1762 } // namespace extensions 1642 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/extension_updater.cc ('k') | chrome/browser/safe_browsing/database_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698