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

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

Issue 666153002: Standardize usage of virtual/override/final in chrome/browser/extensions/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 public: 205 public:
206 NotificationsObserver() { 206 NotificationsObserver() {
207 for (size_t i = 0; i < arraysize(kNotificationsObserved); ++i) { 207 for (size_t i = 0; i < arraysize(kNotificationsObserved); ++i) {
208 count_[i] = 0; 208 count_[i] = 0;
209 registrar_.Add(this, 209 registrar_.Add(this,
210 kNotificationsObserved[i], 210 kNotificationsObserved[i],
211 content::NotificationService::AllSources()); 211 content::NotificationService::AllSources());
212 } 212 }
213 } 213 }
214 214
215 virtual ~NotificationsObserver() { 215 ~NotificationsObserver() override {
216 for (size_t i = 0; i < arraysize(kNotificationsObserved); ++i) { 216 for (size_t i = 0; i < arraysize(kNotificationsObserved); ++i) {
217 registrar_.Remove(this, 217 registrar_.Remove(this,
218 kNotificationsObserved[i], 218 kNotificationsObserved[i],
219 content::NotificationService::AllSources()); 219 content::NotificationService::AllSources());
220 } 220 }
221 } 221 }
222 222
223 size_t StartedCount() { return count_[0]; } 223 size_t StartedCount() { return count_[0]; }
224 size_t UpdatedCount() { return count_[1]; } 224 size_t UpdatedCount() { return count_[1]; }
225 225
226 bool Updated(const std::string& id) { 226 bool Updated(const std::string& id) {
227 return updated_.find(id) != updated_.end(); 227 return updated_.find(id) != updated_.end();
228 } 228 }
229 229
230 void Wait() { 230 void Wait() {
231 scoped_refptr<content::MessageLoopRunner> runner = 231 scoped_refptr<content::MessageLoopRunner> runner =
232 new content::MessageLoopRunner; 232 new content::MessageLoopRunner;
233 quit_closure_ = runner->QuitClosure(); 233 quit_closure_ = runner->QuitClosure();
234 runner->Run(); 234 runner->Run();
235 quit_closure_.Reset(); 235 quit_closure_.Reset();
236 } 236 }
237 237
238 private: 238 private:
239 virtual void Observe(int type, 239 void Observe(int type,
240 const content::NotificationSource& source, 240 const content::NotificationSource& source,
241 const content::NotificationDetails& details) override { 241 const content::NotificationDetails& details) override {
242 if (!quit_closure_.is_null()) 242 if (!quit_closure_.is_null())
243 quit_closure_.Run(); 243 quit_closure_.Run();
244 for (size_t i = 0; i < arraysize(kNotificationsObserved); ++i) { 244 for (size_t i = 0; i < arraysize(kNotificationsObserved); ++i) {
245 if (kNotificationsObserved[i] == type) { 245 if (kNotificationsObserved[i] == type) {
246 count_[i]++; 246 count_[i]++;
247 if (type == extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND) { 247 if (type == extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND) {
248 updated_.insert( 248 updated_.insert(
249 content::Details<UpdateDetails>(details)->id); 249 content::Details<UpdateDetails>(details)->id);
250 } 250 }
251 return; 251 return;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 285
286 // Base class for further specialized test classes. 286 // Base class for further specialized test classes.
287 class MockService : public TestExtensionService { 287 class MockService : public TestExtensionService {
288 public: 288 public:
289 explicit MockService(TestExtensionPrefs* prefs) 289 explicit MockService(TestExtensionPrefs* prefs)
290 : prefs_(prefs), 290 : prefs_(prefs),
291 pending_extension_manager_(&profile_), 291 pending_extension_manager_(&profile_),
292 downloader_delegate_override_(NULL) { 292 downloader_delegate_override_(NULL) {
293 } 293 }
294 294
295 virtual ~MockService() {} 295 ~MockService() override {}
296 296
297 virtual PendingExtensionManager* pending_extension_manager() override { 297 PendingExtensionManager* pending_extension_manager() override {
298 ADD_FAILURE() << "Subclass should override this if it will " 298 ADD_FAILURE() << "Subclass should override this if it will "
299 << "be accessed by a test."; 299 << "be accessed by a test.";
300 return &pending_extension_manager_; 300 return &pending_extension_manager_;
301 } 301 }
302 302
303 Profile* profile() { return &profile_; } 303 Profile* profile() { return &profile_; }
304 304
305 net::URLRequestContextGetter* request_context() { 305 net::URLRequestContextGetter* request_context() {
306 return profile_.GetRequestContext(); 306 return profile_.GetRequestContext();
307 } 307 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 } 428 }
429 } 429 }
430 430
431 class ServiceForManifestTests : public MockService { 431 class ServiceForManifestTests : public MockService {
432 public: 432 public:
433 explicit ServiceForManifestTests(TestExtensionPrefs* prefs) 433 explicit ServiceForManifestTests(TestExtensionPrefs* prefs)
434 : MockService(prefs), 434 : MockService(prefs),
435 registry_(ExtensionRegistry::Get(profile())) { 435 registry_(ExtensionRegistry::Get(profile())) {
436 } 436 }
437 437
438 virtual ~ServiceForManifestTests() {} 438 ~ServiceForManifestTests() override {}
439 439
440 virtual const Extension* GetExtensionById( 440 const Extension* GetExtensionById(const std::string& id,
441 const std::string& id, bool include_disabled) const override { 441 bool include_disabled) const override {
442 const Extension* result = registry_->enabled_extensions().GetByID(id); 442 const Extension* result = registry_->enabled_extensions().GetByID(id);
443 if (result || !include_disabled) 443 if (result || !include_disabled)
444 return result; 444 return result;
445 return registry_->disabled_extensions().GetByID(id); 445 return registry_->disabled_extensions().GetByID(id);
446 } 446 }
447 447
448 virtual const ExtensionSet* extensions() const override { 448 const ExtensionSet* extensions() const override {
449 return &registry_->enabled_extensions(); 449 return &registry_->enabled_extensions();
450 } 450 }
451 451
452 virtual PendingExtensionManager* pending_extension_manager() override { 452 PendingExtensionManager* pending_extension_manager() override {
453 return &pending_extension_manager_; 453 return &pending_extension_manager_;
454 } 454 }
455 455
456 virtual const Extension* GetPendingExtensionUpdate( 456 const Extension* GetPendingExtensionUpdate(
457 const std::string& id) const override { 457 const std::string& id) const override {
458 return NULL; 458 return NULL;
459 } 459 }
460 460
461 virtual bool IsExtensionEnabled(const std::string& id) const override { 461 bool IsExtensionEnabled(const std::string& id) const override {
462 return !registry_->disabled_extensions().Contains(id); 462 return !registry_->disabled_extensions().Contains(id);
463 } 463 }
464 464
465 void set_extensions(ExtensionList extensions, 465 void set_extensions(ExtensionList extensions,
466 ExtensionList disabled_extensions) { 466 ExtensionList disabled_extensions) {
467 registry_->ClearAll(); 467 registry_->ClearAll();
468 for (ExtensionList::const_iterator it = extensions.begin(); 468 for (ExtensionList::const_iterator it = extensions.begin();
469 it != extensions.end(); ++it) { 469 it != extensions.end(); ++it) {
470 registry_->AddEnabled(*it); 470 registry_->AddEnabled(*it);
471 } 471 }
(...skipping 12 matching lines...) Expand all
484 explicit ServiceForDownloadTests(TestExtensionPrefs* prefs) 484 explicit ServiceForDownloadTests(TestExtensionPrefs* prefs)
485 : MockService(prefs) { 485 : MockService(prefs) {
486 } 486 }
487 487
488 // Add a fake crx installer to be returned by a call to UpdateExtension() 488 // Add a fake crx installer to be returned by a call to UpdateExtension()
489 // with a specific ID. Caller keeps ownership of |crx_installer|. 489 // with a specific ID. Caller keeps ownership of |crx_installer|.
490 void AddFakeCrxInstaller(const std::string& id, CrxInstaller* crx_installer) { 490 void AddFakeCrxInstaller(const std::string& id, CrxInstaller* crx_installer) {
491 fake_crx_installers_[id] = crx_installer; 491 fake_crx_installers_[id] = crx_installer;
492 } 492 }
493 493
494 virtual bool UpdateExtension( 494 bool UpdateExtension(const std::string& id,
495 const std::string& id, 495 const base::FilePath& extension_path,
496 const base::FilePath& extension_path, 496 bool file_ownership_passed,
497 bool file_ownership_passed, 497 CrxInstaller** out_crx_installer) override {
498 CrxInstaller** out_crx_installer) override {
499 extension_id_ = id; 498 extension_id_ = id;
500 install_path_ = extension_path; 499 install_path_ = extension_path;
501 500
502 if (ContainsKey(fake_crx_installers_, id)) { 501 if (ContainsKey(fake_crx_installers_, id)) {
503 *out_crx_installer = fake_crx_installers_[id]; 502 *out_crx_installer = fake_crx_installers_[id];
504 return true; 503 return true;
505 } 504 }
506 505
507 return false; 506 return false;
508 } 507 }
509 508
510 virtual PendingExtensionManager* pending_extension_manager() override { 509 PendingExtensionManager* pending_extension_manager() override {
511 return &pending_extension_manager_; 510 return &pending_extension_manager_;
512 } 511 }
513 512
514 virtual const Extension* GetExtensionById( 513 const Extension* GetExtensionById(const std::string& id,
515 const std::string& id, bool) const override { 514 bool) const override {
516 last_inquired_extension_id_ = id; 515 last_inquired_extension_id_ = id;
517 return NULL; 516 return NULL;
518 } 517 }
519 518
520 const std::string& extension_id() const { return extension_id_; } 519 const std::string& extension_id() const { return extension_id_; }
521 const base::FilePath& install_path() const { return install_path_; } 520 const base::FilePath& install_path() const { return install_path_; }
522 521
523 private: 522 private:
524 // Hold the set of ids that UpdateExtension() should fake success on. 523 // Hold the set of ids that UpdateExtension() should fake success on.
525 // UpdateExtension(id, ...) will return true iff fake_crx_installers_ 524 // UpdateExtension(id, ...) will return true iff fake_crx_installers_
(...skipping 1536 matching lines...) Expand 10 before | Expand all | Expand 10 after
2062 // -prodversionmin (shouldn't update if browser version too old) 2061 // -prodversionmin (shouldn't update if browser version too old)
2063 // -manifests & updates arriving out of order / interleaved 2062 // -manifests & updates arriving out of order / interleaved
2064 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 2063 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
2065 // -An extension gets uninstalled while updates are in progress (so it doesn't 2064 // -An extension gets uninstalled while updates are in progress (so it doesn't
2066 // "come back from the dead") 2065 // "come back from the dead")
2067 // -An extension gets manually updated to v3 while we're downloading v2 (ie 2066 // -An extension gets manually updated to v3 while we're downloading v2 (ie
2068 // you don't get downgraded accidentally) 2067 // you don't get downgraded accidentally)
2069 // -An update manifest mentions multiple updates 2068 // -An update manifest mentions multiple updates
2070 2069
2071 } // namespace extensions 2070 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/extension_updater.h ('k') | chrome/browser/extensions/user_script_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698