| OLD | NEW |
| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 virtual 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 virtual ~MockService() {} |
| 296 | 296 |
| 297 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE { | 297 virtual 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 class ServiceForManifestTests : public MockService { | 434 class ServiceForManifestTests : public MockService { |
| 435 public: | 435 public: |
| 436 explicit ServiceForManifestTests(TestExtensionPrefs* prefs) | 436 explicit ServiceForManifestTests(TestExtensionPrefs* prefs) |
| 437 : MockService(prefs), | 437 : MockService(prefs), |
| 438 registry_(ExtensionRegistry::Get(profile())) { | 438 registry_(ExtensionRegistry::Get(profile())) { |
| 439 } | 439 } |
| 440 | 440 |
| 441 virtual ~ServiceForManifestTests() {} | 441 virtual ~ServiceForManifestTests() {} |
| 442 | 442 |
| 443 virtual const Extension* GetExtensionById( | 443 virtual const Extension* GetExtensionById( |
| 444 const std::string& id, bool include_disabled) const OVERRIDE { | 444 const std::string& id, bool include_disabled) const override { |
| 445 const Extension* result = registry_->enabled_extensions().GetByID(id); | 445 const Extension* result = registry_->enabled_extensions().GetByID(id); |
| 446 if (result || !include_disabled) | 446 if (result || !include_disabled) |
| 447 return result; | 447 return result; |
| 448 return registry_->disabled_extensions().GetByID(id); | 448 return registry_->disabled_extensions().GetByID(id); |
| 449 } | 449 } |
| 450 | 450 |
| 451 virtual const ExtensionSet* extensions() const OVERRIDE { | 451 virtual const ExtensionSet* extensions() const override { |
| 452 return ®istry_->enabled_extensions(); | 452 return ®istry_->enabled_extensions(); |
| 453 } | 453 } |
| 454 | 454 |
| 455 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE { | 455 virtual PendingExtensionManager* pending_extension_manager() override { |
| 456 return &pending_extension_manager_; | 456 return &pending_extension_manager_; |
| 457 } | 457 } |
| 458 | 458 |
| 459 virtual const Extension* GetPendingExtensionUpdate( | 459 virtual const Extension* GetPendingExtensionUpdate( |
| 460 const std::string& id) const OVERRIDE { | 460 const std::string& id) const override { |
| 461 return NULL; | 461 return NULL; |
| 462 } | 462 } |
| 463 | 463 |
| 464 virtual bool IsExtensionEnabled(const std::string& id) const OVERRIDE { | 464 virtual bool IsExtensionEnabled(const std::string& id) const override { |
| 465 return !registry_->disabled_extensions().Contains(id); | 465 return !registry_->disabled_extensions().Contains(id); |
| 466 } | 466 } |
| 467 | 467 |
| 468 void set_extensions(ExtensionList extensions, | 468 void set_extensions(ExtensionList extensions, |
| 469 ExtensionList disabled_extensions) { | 469 ExtensionList disabled_extensions) { |
| 470 registry_->ClearAll(); | 470 registry_->ClearAll(); |
| 471 for (ExtensionList::const_iterator it = extensions.begin(); | 471 for (ExtensionList::const_iterator it = extensions.begin(); |
| 472 it != extensions.end(); ++it) { | 472 it != extensions.end(); ++it) { |
| 473 registry_->AddEnabled(*it); | 473 registry_->AddEnabled(*it); |
| 474 } | 474 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 491 // Add a fake crx installer to be returned by a call to UpdateExtension() | 491 // Add a fake crx installer to be returned by a call to UpdateExtension() |
| 492 // with a specific ID. Caller keeps ownership of |crx_installer|. | 492 // with a specific ID. Caller keeps ownership of |crx_installer|. |
| 493 void AddFakeCrxInstaller(const std::string& id, CrxInstaller* crx_installer) { | 493 void AddFakeCrxInstaller(const std::string& id, CrxInstaller* crx_installer) { |
| 494 fake_crx_installers_[id] = crx_installer; | 494 fake_crx_installers_[id] = crx_installer; |
| 495 } | 495 } |
| 496 | 496 |
| 497 virtual bool UpdateExtension( | 497 virtual bool UpdateExtension( |
| 498 const std::string& id, | 498 const std::string& id, |
| 499 const base::FilePath& extension_path, | 499 const base::FilePath& extension_path, |
| 500 bool file_ownership_passed, | 500 bool file_ownership_passed, |
| 501 CrxInstaller** out_crx_installer) OVERRIDE { | 501 CrxInstaller** out_crx_installer) override { |
| 502 extension_id_ = id; | 502 extension_id_ = id; |
| 503 install_path_ = extension_path; | 503 install_path_ = extension_path; |
| 504 | 504 |
| 505 if (ContainsKey(fake_crx_installers_, id)) { | 505 if (ContainsKey(fake_crx_installers_, id)) { |
| 506 *out_crx_installer = fake_crx_installers_[id]; | 506 *out_crx_installer = fake_crx_installers_[id]; |
| 507 return true; | 507 return true; |
| 508 } | 508 } |
| 509 | 509 |
| 510 return false; | 510 return false; |
| 511 } | 511 } |
| 512 | 512 |
| 513 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE { | 513 virtual PendingExtensionManager* pending_extension_manager() override { |
| 514 return &pending_extension_manager_; | 514 return &pending_extension_manager_; |
| 515 } | 515 } |
| 516 | 516 |
| 517 virtual const Extension* GetExtensionById( | 517 virtual const Extension* GetExtensionById( |
| 518 const std::string& id, bool) const OVERRIDE { | 518 const std::string& id, bool) const override { |
| 519 last_inquired_extension_id_ = id; | 519 last_inquired_extension_id_ = id; |
| 520 return NULL; | 520 return NULL; |
| 521 } | 521 } |
| 522 | 522 |
| 523 const std::string& extension_id() const { return extension_id_; } | 523 const std::string& extension_id() const { return extension_id_; } |
| 524 const base::FilePath& install_path() const { return install_path_; } | 524 const base::FilePath& install_path() const { return install_path_; } |
| 525 | 525 |
| 526 private: | 526 private: |
| 527 // Hold the set of ids that UpdateExtension() should fake success on. | 527 // Hold the set of ids that UpdateExtension() should fake success on. |
| 528 // UpdateExtension(id, ...) will return true iff fake_crx_installers_ | 528 // UpdateExtension(id, ...) will return true iff fake_crx_installers_ |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 | 587 |
| 588 // All of our tests that need to use private APIs of ExtensionUpdater live | 588 // All of our tests that need to use private APIs of ExtensionUpdater live |
| 589 // inside this class (which is a friend to ExtensionUpdater). | 589 // inside this class (which is a friend to ExtensionUpdater). |
| 590 class ExtensionUpdaterTest : public testing::Test { | 590 class ExtensionUpdaterTest : public testing::Test { |
| 591 public: | 591 public: |
| 592 ExtensionUpdaterTest() | 592 ExtensionUpdaterTest() |
| 593 : thread_bundle_( | 593 : thread_bundle_( |
| 594 content::TestBrowserThreadBundle::IO_MAINLOOP) { | 594 content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| 595 } | 595 } |
| 596 | 596 |
| 597 virtual void SetUp() OVERRIDE { | 597 virtual void SetUp() override { |
| 598 prefs_.reset(new TestExtensionPrefs(base::MessageLoopProxy::current())); | 598 prefs_.reset(new TestExtensionPrefs(base::MessageLoopProxy::current())); |
| 599 } | 599 } |
| 600 | 600 |
| 601 virtual void TearDown() OVERRIDE { | 601 virtual void TearDown() override { |
| 602 // Some tests create URLRequestContextGetters, whose destruction must run | 602 // Some tests create URLRequestContextGetters, whose destruction must run |
| 603 // on the IO thread. Make sure the IO loop spins before shutdown so that | 603 // on the IO thread. Make sure the IO loop spins before shutdown so that |
| 604 // those objects are released. | 604 // those objects are released. |
| 605 RunUntilIdle(); | 605 RunUntilIdle(); |
| 606 prefs_.reset(); | 606 prefs_.reset(); |
| 607 } | 607 } |
| 608 | 608 |
| 609 void RunUntilIdle() { | 609 void RunUntilIdle() { |
| 610 prefs_->pref_service()->CommitPendingWrite(); | 610 prefs_->pref_service()->CommitPendingWrite(); |
| 611 base::RunLoop().RunUntilIdle(); | 611 base::RunLoop().RunUntilIdle(); |
| (...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2067 // -prodversionmin (shouldn't update if browser version too old) | 2067 // -prodversionmin (shouldn't update if browser version too old) |
| 2068 // -manifests & updates arriving out of order / interleaved | 2068 // -manifests & updates arriving out of order / interleaved |
| 2069 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 2069 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
| 2070 // -An extension gets uninstalled while updates are in progress (so it doesn't | 2070 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 2071 // "come back from the dead") | 2071 // "come back from the dead") |
| 2072 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 2072 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 2073 // you don't get downgraded accidentally) | 2073 // you don't get downgraded accidentally) |
| 2074 // -An update manifest mentions multiple updates | 2074 // -An update manifest mentions multiple updates |
| 2075 | 2075 |
| 2076 } // namespace extensions | 2076 } // namespace extensions |
| OLD | NEW |