Chromium Code Reviews| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 | 120 |
| 121 const char kAuthUserQueryKey[] = "authuser"; | 121 const char kAuthUserQueryKey[] = "authuser"; |
| 122 | 122 |
| 123 int kExpectedLoadFlags = | 123 int kExpectedLoadFlags = |
| 124 net::LOAD_DO_NOT_SEND_COOKIES | | 124 net::LOAD_DO_NOT_SEND_COOKIES | |
| 125 net::LOAD_DO_NOT_SAVE_COOKIES | | 125 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 126 net::LOAD_DISABLE_CACHE; | 126 net::LOAD_DISABLE_CACHE; |
| 127 | 127 |
| 128 int kExpectedLoadFlagsForDownloadWithCookies = net::LOAD_DISABLE_CACHE; | 128 int kExpectedLoadFlagsForDownloadWithCookies = net::LOAD_DISABLE_CACHE; |
| 129 | 129 |
| 130 // Fake authentication constants | |
| 131 const char kFakeAccountId[] = "bobloblaw@lawblog.example.com"; | |
| 132 const char kFakeOAuth2Token[] = "ce n'est pas un jeton"; | |
| 133 | |
| 130 const ManifestFetchData::PingData kNeverPingedData( | 134 const ManifestFetchData::PingData kNeverPingedData( |
| 131 ManifestFetchData::kNeverPinged, ManifestFetchData::kNeverPinged, true); | 135 ManifestFetchData::kNeverPinged, ManifestFetchData::kNeverPinged, true); |
| 132 | 136 |
| 133 class MockExtensionDownloaderDelegate : public ExtensionDownloaderDelegate { | 137 class MockExtensionDownloaderDelegate : public ExtensionDownloaderDelegate { |
| 134 public: | 138 public: |
| 135 MOCK_METHOD4(OnExtensionDownloadFailed, void(const std::string&, | 139 MOCK_METHOD4(OnExtensionDownloadFailed, void(const std::string&, |
| 136 Error, | 140 Error, |
| 137 const PingResult&, | 141 const PingResult&, |
| 138 const std::set<int>&)); | 142 const std::set<int>&)); |
| 139 MOCK_METHOD7(OnExtensionDownloadFinished, void(const std::string&, | 143 MOCK_METHOD7(OnExtensionDownloadFinished, void(const std::string&, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 } | 277 } |
| 274 return 0; | 278 return 0; |
| 275 } | 279 } |
| 276 | 280 |
| 277 } // namespace | 281 } // namespace |
| 278 | 282 |
| 279 // Base class for further specialized test classes. | 283 // Base class for further specialized test classes. |
| 280 class MockService : public TestExtensionService { | 284 class MockService : public TestExtensionService { |
| 281 public: | 285 public: |
| 282 explicit MockService(TestExtensionPrefs* prefs) | 286 explicit MockService(TestExtensionPrefs* prefs) |
| 283 : prefs_(prefs), pending_extension_manager_(&profile_) {} | 287 : prefs_(prefs), |
| 288 pending_extension_manager_(&profile_), | |
| 289 downloader_delegate_override_(NULL) { | |
| 290 } | |
| 284 | 291 |
| 285 virtual ~MockService() {} | 292 virtual ~MockService() {} |
| 286 | 293 |
| 287 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE { | 294 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE { |
| 288 ADD_FAILURE() << "Subclass should override this if it will " | 295 ADD_FAILURE() << "Subclass should override this if it will " |
| 289 << "be accessed by a test."; | 296 << "be accessed by a test."; |
| 290 return &pending_extension_manager_; | 297 return &pending_extension_manager_; |
| 291 } | 298 } |
| 292 | 299 |
| 293 Profile* profile() { return &profile_; } | 300 Profile* profile() { return &profile_; } |
| 294 | 301 |
| 295 net::URLRequestContextGetter* request_context() { | 302 net::URLRequestContextGetter* request_context() { |
| 296 return profile_.GetRequestContext(); | 303 return profile_.GetRequestContext(); |
| 297 } | 304 } |
| 298 | 305 |
| 299 ExtensionPrefs* extension_prefs() { return prefs_->prefs(); } | 306 ExtensionPrefs* extension_prefs() { return prefs_->prefs(); } |
| 300 | 307 |
| 301 PrefService* pref_service() { return prefs_->pref_service(); } | 308 PrefService* pref_service() { return prefs_->pref_service(); } |
| 302 | 309 |
| 310 FakeOAuth2TokenService* fake_token_service() { | |
| 311 return fake_token_service_.get(); | |
| 312 } | |
| 313 | |
| 303 // Creates test extensions and inserts them into list. The name and | 314 // Creates test extensions and inserts them into list. The name and |
| 304 // version are all based on their index. If |update_url| is non-null, it | 315 // version are all based on their index. If |update_url| is non-null, it |
| 305 // will be used as the update_url for each extension. | 316 // will be used as the update_url for each extension. |
| 306 // The |id| is used to distinguish extension names and make sure that | 317 // The |id| is used to distinguish extension names and make sure that |
| 307 // no two extensions share the same name. | 318 // no two extensions share the same name. |
| 308 void CreateTestExtensions(int id, int count, ExtensionList *list, | 319 void CreateTestExtensions(int id, int count, ExtensionList *list, |
| 309 const std::string* update_url, | 320 const std::string* update_url, |
| 310 Manifest::Location location) { | 321 Manifest::Location location) { |
| 311 for (int i = 1; i <= count; i++) { | 322 for (int i = 1; i <= count; i++) { |
| 312 base::DictionaryValue manifest; | 323 base::DictionaryValue manifest; |
| 313 manifest.SetString(manifest_keys::kVersion, | 324 manifest.SetString(manifest_keys::kVersion, |
| 314 base::StringPrintf("%d.0.0.0", i)); | 325 base::StringPrintf("%d.0.0.0", i)); |
| 315 manifest.SetString(manifest_keys::kName, | 326 manifest.SetString(manifest_keys::kName, |
| 316 base::StringPrintf("Extension %d.%d", id, i)); | 327 base::StringPrintf("Extension %d.%d", id, i)); |
| 317 if (update_url) | 328 if (update_url) |
| 318 manifest.SetString(manifest_keys::kUpdateURL, *update_url); | 329 manifest.SetString(manifest_keys::kUpdateURL, *update_url); |
| 319 scoped_refptr<Extension> e = | 330 scoped_refptr<Extension> e = |
| 320 prefs_->AddExtensionWithManifest(manifest, location); | 331 prefs_->AddExtensionWithManifest(manifest, location); |
| 321 ASSERT_TRUE(e.get() != NULL); | 332 ASSERT_TRUE(e.get() != NULL); |
| 322 list->push_back(e); | 333 list->push_back(e); |
| 323 } | 334 } |
| 324 } | 335 } |
| 325 | 336 |
| 337 ExtensionDownloader::Factory GetDownloaderFactory() { | |
| 338 return base::Bind(&MockService::CreateExtensionDownloader, | |
| 339 base::Unretained(this)); | |
| 340 } | |
| 341 | |
| 342 ExtensionDownloader::Factory GetAuthenticatedDownloaderFactory() { | |
| 343 return base::Bind(&MockService::CreateExtensionDownloaderWithIdentity, | |
| 344 base::Unretained(this)); | |
| 345 } | |
| 346 | |
| 347 void OverrideDownloaderDelegate(ExtensionDownloaderDelegate* delegate) { | |
| 348 downloader_delegate_override_ = delegate; | |
| 349 } | |
| 350 | |
| 326 protected: | 351 protected: |
| 327 TestExtensionPrefs* const prefs_; | 352 TestExtensionPrefs* const prefs_; |
| 328 TestingProfile profile_; | 353 TestingProfile profile_; |
| 329 PendingExtensionManager pending_extension_manager_; | 354 PendingExtensionManager pending_extension_manager_; |
| 330 | 355 |
| 331 private: | 356 private: |
| 357 scoped_ptr<ExtensionDownloader> CreateExtensionDownloader( | |
| 358 ExtensionDownloaderDelegate* delegate) { | |
| 359 return make_scoped_ptr(new ExtensionDownloader( | |
| 360 downloader_delegate_override_ ? downloader_delegate_override_ | |
| 361 : delegate, | |
| 362 request_context())); | |
| 363 } | |
| 364 | |
| 365 scoped_ptr<ExtensionDownloader> CreateExtensionDownloaderWithIdentity( | |
| 366 ExtensionDownloaderDelegate* delegate) { | |
| 367 scoped_ptr<FakeIdentityProvider> fake_identity_provider; | |
| 368 fake_token_service_.reset(new FakeOAuth2TokenService()); | |
| 369 fake_identity_provider.reset(new FakeIdentityProvider( | |
| 370 fake_token_service_.get())); | |
| 371 fake_identity_provider->LogIn(kFakeAccountId); | |
| 372 fake_token_service_->AddAccount(kFakeAccountId); | |
| 373 | |
| 374 scoped_ptr<ExtensionDownloader> downloader(new ExtensionDownloader( | |
|
Yoyo Zhou
2014/08/11 23:19:28
Use CreateExtensionDownloader here.
Ken Rockot(use gerrit already)
2014/08/11 23:48:25
Good catch, thanks. Done.
| |
| 375 downloader_delegate_override_ ? downloader_delegate_override_ | |
| 376 : delegate, | |
| 377 request_context())); | |
| 378 downloader->SetWebstoreIdentityProvider( | |
| 379 fake_identity_provider.PassAs<IdentityProvider>()); | |
| 380 return downloader.Pass(); | |
| 381 } | |
| 382 | |
| 383 scoped_ptr<FakeOAuth2TokenService> fake_token_service_; | |
| 384 | |
| 385 ExtensionDownloaderDelegate* downloader_delegate_override_; | |
| 386 | |
| 332 DISALLOW_COPY_AND_ASSIGN(MockService); | 387 DISALLOW_COPY_AND_ASSIGN(MockService); |
| 333 }; | 388 }; |
| 334 | 389 |
| 335 | 390 |
| 336 bool ShouldInstallExtensionsOnly(const Extension* extension) { | 391 bool ShouldInstallExtensionsOnly(const Extension* extension) { |
| 337 return extension->GetType() == Manifest::TYPE_EXTENSION; | 392 return extension->GetType() == Manifest::TYPE_EXTENSION; |
| 338 } | 393 } |
| 339 | 394 |
| 340 bool ShouldInstallThemesOnly(const Extension* extension) { | 395 bool ShouldInstallThemesOnly(const Extension* extension) { |
| 341 return extension->is_theme(); | 396 return extension->is_theme(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 370 Manifest::INTERNAL, | 425 Manifest::INTERNAL, |
| 371 Extension::NO_FLAGS, | 426 Extension::NO_FLAGS, |
| 372 kMarkAcknowledged, | 427 kMarkAcknowledged, |
| 373 kRemoteInstall)); | 428 kRemoteInstall)); |
| 374 } | 429 } |
| 375 } | 430 } |
| 376 | 431 |
| 377 class ServiceForManifestTests : public MockService { | 432 class ServiceForManifestTests : public MockService { |
| 378 public: | 433 public: |
| 379 explicit ServiceForManifestTests(TestExtensionPrefs* prefs) | 434 explicit ServiceForManifestTests(TestExtensionPrefs* prefs) |
| 380 : MockService(prefs), registry_(ExtensionRegistry::Get(profile())) {} | 435 : MockService(prefs), |
| 436 registry_(ExtensionRegistry::Get(profile())) { | |
| 437 } | |
| 381 | 438 |
| 382 virtual ~ServiceForManifestTests() {} | 439 virtual ~ServiceForManifestTests() {} |
| 383 | 440 |
| 384 virtual const Extension* GetExtensionById( | 441 virtual const Extension* GetExtensionById( |
| 385 const std::string& id, bool include_disabled) const OVERRIDE { | 442 const std::string& id, bool include_disabled) const OVERRIDE { |
| 386 const Extension* result = registry_->enabled_extensions().GetByID(id); | 443 const Extension* result = registry_->enabled_extensions().GetByID(id); |
| 387 if (result || !include_disabled) | 444 if (result || !include_disabled) |
| 388 return result; | 445 return result; |
| 389 return registry_->disabled_extensions().GetByID(id); | 446 return registry_->disabled_extensions().GetByID(id); |
| 390 } | 447 } |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 const std::string& version, | 621 const std::string& version, |
| 565 const std::string& url, | 622 const std::string& url, |
| 566 UpdateManifest::Results* results) { | 623 UpdateManifest::Results* results) { |
| 567 UpdateManifest::Result result; | 624 UpdateManifest::Result result; |
| 568 result.extension_id = id; | 625 result.extension_id = id; |
| 569 result.version = version; | 626 result.version = version; |
| 570 result.crx_url = GURL(url); | 627 result.crx_url = GURL(url); |
| 571 results->list.push_back(result); | 628 results->list.push_back(result); |
| 572 } | 629 } |
| 573 | 630 |
| 574 void ResetDownloader(ExtensionUpdater* updater, | |
| 575 ExtensionDownloader* downloader) { | |
| 576 EXPECT_FALSE(updater->downloader_.get()); | |
| 577 updater->downloader_.reset(downloader); | |
| 578 } | |
| 579 | |
| 580 void StartUpdateCheck(ExtensionDownloader* downloader, | 631 void StartUpdateCheck(ExtensionDownloader* downloader, |
| 581 ManifestFetchData* fetch_data) { | 632 ManifestFetchData* fetch_data) { |
| 582 downloader->StartUpdateCheck(scoped_ptr<ManifestFetchData>(fetch_data)); | 633 downloader->StartUpdateCheck(scoped_ptr<ManifestFetchData>(fetch_data)); |
| 583 } | 634 } |
| 584 | 635 |
| 585 size_t ManifestFetchersCount(ExtensionDownloader* downloader) { | 636 size_t ManifestFetchersCount(ExtensionDownloader* downloader) { |
| 586 return downloader->manifests_queue_.size() + | 637 return downloader->manifests_queue_.size() + |
| 587 (downloader->manifest_fetcher_.get() ? 1 : 0); | 638 (downloader->manifest_fetcher_.get() ? 1 : 0); |
| 588 } | 639 } |
| 589 | 640 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 605 } | 656 } |
| 606 | 657 |
| 607 // Set up and start the updater. | 658 // Set up and start the updater. |
| 608 net::TestURLFetcherFactory factory; | 659 net::TestURLFetcherFactory factory; |
| 609 ExtensionUpdater updater(&service, | 660 ExtensionUpdater updater(&service, |
| 610 service.extension_prefs(), | 661 service.extension_prefs(), |
| 611 service.pref_service(), | 662 service.pref_service(), |
| 612 service.profile(), | 663 service.profile(), |
| 613 60 * 60 * 24, | 664 60 * 60 * 24, |
| 614 NULL, | 665 NULL, |
| 615 make_scoped_ptr<IdentityProvider>(NULL)); | 666 service.GetDownloaderFactory()); |
| 616 updater.Start(); | 667 updater.Start(); |
| 617 | 668 |
| 618 // Tell the update that it's time to do update checks. | 669 // Tell the update that it's time to do update checks. |
| 619 EXPECT_EQ(0u, observer.StartedCount()); | 670 EXPECT_EQ(0u, observer.StartedCount()); |
| 620 SimulateTimerFired(&updater); | 671 SimulateTimerFired(&updater); |
| 621 EXPECT_EQ(1u, observer.StartedCount()); | 672 EXPECT_EQ(1u, observer.StartedCount()); |
| 622 | 673 |
| 623 // Get the url our mock fetcher was asked to fetch. | 674 // Get the url our mock fetcher was asked to fetch. |
| 624 net::TestURLFetcher* fetcher = | 675 net::TestURLFetcher* fetcher = |
| 625 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 676 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 EXPECT_EQ(id, params["id"]); | 743 EXPECT_EQ(id, params["id"]); |
| 693 EXPECT_EQ(version, params["v"]); | 744 EXPECT_EQ(version, params["v"]); |
| 694 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); | 745 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); |
| 695 } | 746 } |
| 696 | 747 |
| 697 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { | 748 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { |
| 698 net::TestURLFetcherFactory factory; | 749 net::TestURLFetcherFactory factory; |
| 699 | 750 |
| 700 MockService service(prefs_.get()); | 751 MockService service(prefs_.get()); |
| 701 MockExtensionDownloaderDelegate delegate; | 752 MockExtensionDownloaderDelegate delegate; |
| 702 ExtensionDownloader downloader(&delegate, service.request_context(), NULL); | 753 ExtensionDownloader downloader(&delegate, service.request_context()); |
| 703 ExtensionList extensions; | 754 ExtensionList extensions; |
| 704 std::string url(gallery_url); | 755 std::string url(gallery_url); |
| 705 | 756 |
| 706 service.CreateTestExtensions(1, 1, &extensions, &url, Manifest::INTERNAL); | 757 service.CreateTestExtensions(1, 1, &extensions, &url, Manifest::INTERNAL); |
| 707 | 758 |
| 708 const std::string& id = extensions[0]->id(); | 759 const std::string& id = extensions[0]->id(); |
| 709 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)); | 760 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)); |
| 710 | 761 |
| 711 downloader.AddExtension(*extensions[0].get(), 0); | 762 downloader.AddExtension(*extensions[0].get(), 0); |
| 712 downloader.StartAllPending(NULL); | 763 downloader.StartAllPending(NULL); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 734 std::map<std::string, std::string> params; | 785 std::map<std::string, std::string> params; |
| 735 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 786 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); |
| 736 EXPECT_EQ(id, params["id"]); | 787 EXPECT_EQ(id, params["id"]); |
| 737 EXPECT_EQ(version, params["v"]); | 788 EXPECT_EQ(version, params["v"]); |
| 738 EXPECT_EQ(install_source, params["installsource"]); | 789 EXPECT_EQ(install_source, params["installsource"]); |
| 739 } | 790 } |
| 740 | 791 |
| 741 void TestDetermineUpdates() { | 792 void TestDetermineUpdates() { |
| 742 TestingProfile profile; | 793 TestingProfile profile; |
| 743 MockExtensionDownloaderDelegate delegate; | 794 MockExtensionDownloaderDelegate delegate; |
| 744 ExtensionDownloader downloader( | 795 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); |
| 745 &delegate, profile.GetRequestContext(), NULL); | |
| 746 | 796 |
| 747 // Check passing an empty list of parse results to DetermineUpdates | 797 // Check passing an empty list of parse results to DetermineUpdates |
| 748 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 798 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); |
| 749 UpdateManifest::Results updates; | 799 UpdateManifest::Results updates; |
| 750 std::vector<int> updateable; | 800 std::vector<int> updateable; |
| 751 downloader.DetermineUpdates(fetch_data, updates, &updateable); | 801 downloader.DetermineUpdates(fetch_data, updates, &updateable); |
| 752 EXPECT_TRUE(updateable.empty()); | 802 EXPECT_TRUE(updateable.empty()); |
| 753 | 803 |
| 754 // Create two updates - expect that DetermineUpdates will return the first | 804 // Create two updates - expect that DetermineUpdates will return the first |
| 755 // one (v1.0 installed, v1.1 available) but not the second one (both | 805 // one (v1.0 installed, v1.1 available) but not the second one (both |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 778 | 828 |
| 779 void TestDetermineUpdatesPending() { | 829 void TestDetermineUpdatesPending() { |
| 780 // Create a set of test extensions | 830 // Create a set of test extensions |
| 781 ServiceForManifestTests service(prefs_.get()); | 831 ServiceForManifestTests service(prefs_.get()); |
| 782 PendingExtensionManager* pending_extension_manager = | 832 PendingExtensionManager* pending_extension_manager = |
| 783 service.pending_extension_manager(); | 833 service.pending_extension_manager(); |
| 784 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); | 834 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); |
| 785 | 835 |
| 786 TestingProfile profile; | 836 TestingProfile profile; |
| 787 MockExtensionDownloaderDelegate delegate; | 837 MockExtensionDownloaderDelegate delegate; |
| 788 ExtensionDownloader downloader( | 838 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); |
| 789 &delegate, profile.GetRequestContext(), NULL); | |
| 790 | 839 |
| 791 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 840 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); |
| 792 UpdateManifest::Results updates; | 841 UpdateManifest::Results updates; |
| 793 | 842 |
| 794 std::list<std::string> ids_for_update_check; | 843 std::list<std::string> ids_for_update_check; |
| 795 pending_extension_manager->GetPendingIdsForUpdateCheck( | 844 pending_extension_manager->GetPendingIdsForUpdateCheck( |
| 796 &ids_for_update_check); | 845 &ids_for_update_check); |
| 797 | 846 |
| 798 std::list<std::string>::const_iterator it; | 847 std::list<std::string>::const_iterator it; |
| 799 for (it = ids_for_update_check.begin(); | 848 for (it = ids_for_update_check.begin(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 818 EXPECT_EQ(static_cast<int>(i), updateable[i]); | 867 EXPECT_EQ(static_cast<int>(i), updateable[i]); |
| 819 } | 868 } |
| 820 } | 869 } |
| 821 | 870 |
| 822 void TestMultipleManifestDownloading() { | 871 void TestMultipleManifestDownloading() { |
| 823 net::TestURLFetcherFactory factory; | 872 net::TestURLFetcherFactory factory; |
| 824 factory.set_remove_fetcher_on_delete(true); | 873 factory.set_remove_fetcher_on_delete(true); |
| 825 net::TestURLFetcher* fetcher = NULL; | 874 net::TestURLFetcher* fetcher = NULL; |
| 826 MockService service(prefs_.get()); | 875 MockService service(prefs_.get()); |
| 827 MockExtensionDownloaderDelegate delegate; | 876 MockExtensionDownloaderDelegate delegate; |
| 828 ExtensionDownloader downloader(&delegate, service.request_context(), NULL); | 877 ExtensionDownloader downloader(&delegate, service.request_context()); |
| 829 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); | 878 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); |
| 830 | 879 |
| 831 GURL kUpdateUrl("http://localhost/manifest1"); | 880 GURL kUpdateUrl("http://localhost/manifest1"); |
| 832 | 881 |
| 833 scoped_ptr<ManifestFetchData> fetch1(new ManifestFetchData(kUpdateUrl, 0)); | 882 scoped_ptr<ManifestFetchData> fetch1(new ManifestFetchData(kUpdateUrl, 0)); |
| 834 scoped_ptr<ManifestFetchData> fetch2(new ManifestFetchData(kUpdateUrl, 0)); | 883 scoped_ptr<ManifestFetchData> fetch2(new ManifestFetchData(kUpdateUrl, 0)); |
| 835 scoped_ptr<ManifestFetchData> fetch3(new ManifestFetchData(kUpdateUrl, 0)); | 884 scoped_ptr<ManifestFetchData> fetch3(new ManifestFetchData(kUpdateUrl, 0)); |
| 836 scoped_ptr<ManifestFetchData> fetch4(new ManifestFetchData(kUpdateUrl, 0)); | 885 scoped_ptr<ManifestFetchData> fetch4(new ManifestFetchData(kUpdateUrl, 0)); |
| 837 ManifestFetchData::PingData zeroDays(0, 0, true); | 886 ManifestFetchData::PingData zeroDays(0, 0, true); |
| 838 fetch1->AddExtension( | 887 fetch1->AddExtension( |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 958 if (fetcher) | 1007 if (fetcher) |
| 959 ADD_FAILURE() << "Unexpected fetch: " << fetcher->GetOriginalURL(); | 1008 ADD_FAILURE() << "Unexpected fetch: " << fetcher->GetOriginalURL(); |
| 960 } | 1009 } |
| 961 | 1010 |
| 962 void TestManifestRetryDownloading() { | 1011 void TestManifestRetryDownloading() { |
| 963 net::TestURLFetcherFactory factory; | 1012 net::TestURLFetcherFactory factory; |
| 964 net::TestURLFetcher* fetcher = NULL; | 1013 net::TestURLFetcher* fetcher = NULL; |
| 965 NotificationsObserver observer; | 1014 NotificationsObserver observer; |
| 966 MockService service(prefs_.get()); | 1015 MockService service(prefs_.get()); |
| 967 MockExtensionDownloaderDelegate delegate; | 1016 MockExtensionDownloaderDelegate delegate; |
| 968 ExtensionDownloader downloader(&delegate, service.request_context(), NULL); | 1017 ExtensionDownloader downloader(&delegate, service.request_context()); |
| 969 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); | 1018 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); |
| 970 | 1019 |
| 971 GURL kUpdateUrl("http://localhost/manifest1"); | 1020 GURL kUpdateUrl("http://localhost/manifest1"); |
| 972 | 1021 |
| 973 scoped_ptr<ManifestFetchData> fetch(new ManifestFetchData(kUpdateUrl, 0)); | 1022 scoped_ptr<ManifestFetchData> fetch(new ManifestFetchData(kUpdateUrl, 0)); |
| 974 ManifestFetchData::PingData zeroDays(0, 0, true); | 1023 ManifestFetchData::PingData zeroDays(0, 0, true); |
| 975 fetch->AddExtension( | 1024 fetch->AddExtension( |
| 976 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 1025 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); |
| 977 | 1026 |
| 978 // This will start the first fetcher. | 1027 // This will start the first fetcher. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1037 net::TestURLFetcherFactory factory; | 1086 net::TestURLFetcherFactory factory; |
| 1038 net::TestURLFetcher* fetcher = NULL; | 1087 net::TestURLFetcher* fetcher = NULL; |
| 1039 scoped_ptr<ServiceForDownloadTests> service( | 1088 scoped_ptr<ServiceForDownloadTests> service( |
| 1040 new ServiceForDownloadTests(prefs_.get())); | 1089 new ServiceForDownloadTests(prefs_.get())); |
| 1041 ExtensionUpdater updater(service.get(), | 1090 ExtensionUpdater updater(service.get(), |
| 1042 service->extension_prefs(), | 1091 service->extension_prefs(), |
| 1043 service->pref_service(), | 1092 service->pref_service(), |
| 1044 service->profile(), | 1093 service->profile(), |
| 1045 kUpdateFrequencySecs, | 1094 kUpdateFrequencySecs, |
| 1046 NULL, | 1095 NULL, |
| 1047 make_scoped_ptr<IdentityProvider>(NULL)); | 1096 service->GetDownloaderFactory()); |
| 1048 updater.Start(); | |
| 1049 MockExtensionDownloaderDelegate delegate; | 1097 MockExtensionDownloaderDelegate delegate; |
| 1050 delegate.DelegateTo(&updater); | 1098 delegate.DelegateTo(&updater); |
| 1051 ResetDownloader( | 1099 service->OverrideDownloaderDelegate(&delegate); |
| 1052 &updater, | 1100 updater.Start(); |
| 1053 new ExtensionDownloader(&delegate, service->request_context(), NULL)); | 1101 updater.EnsureDownloaderCreated(); |
| 1054 updater.downloader_->extensions_queue_.set_backoff_policy( | 1102 updater.downloader_->extensions_queue_.set_backoff_policy( |
| 1055 &kNoBackoffPolicy); | 1103 &kNoBackoffPolicy); |
| 1056 | 1104 |
| 1057 GURL test_url("http://localhost/extension.crx"); | 1105 GURL test_url("http://localhost/extension.crx"); |
| 1058 | 1106 |
| 1059 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 1107 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 1060 std::string hash; | 1108 std::string hash; |
| 1061 Version version("0.0.1"); | 1109 Version version("0.0.1"); |
| 1062 std::set<int> requests; | 1110 std::set<int> requests; |
| 1063 requests.insert(0); | 1111 requests.insert(0); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1139 // initially responds with a 403 status. If |identity_provider| is not NULL, | 1187 // initially responds with a 403 status. If |identity_provider| is not NULL, |
| 1140 // this will first expect a request which includes an Authorization header | 1188 // this will first expect a request which includes an Authorization header |
| 1141 // with an OAuth2 bearer token; otherwise, or if OAuth2 failure is simulated, | 1189 // with an OAuth2 bearer token; otherwise, or if OAuth2 failure is simulated, |
| 1142 // this expects the downloader to fall back onto cookie-based credentials. | 1190 // this expects the downloader to fall back onto cookie-based credentials. |
| 1143 void TestProtectedDownload( | 1191 void TestProtectedDownload( |
| 1144 const std::string& url_prefix, | 1192 const std::string& url_prefix, |
| 1145 bool enable_oauth2, | 1193 bool enable_oauth2, |
| 1146 bool succeed_with_oauth2, | 1194 bool succeed_with_oauth2, |
| 1147 int valid_authuser, | 1195 int valid_authuser, |
| 1148 int max_authuser) { | 1196 int max_authuser) { |
| 1149 const char kFakeAccountId[] = "bobloblaw@lawblog.example.com"; | |
| 1150 const char kFakeOAuth2Token[] = "ce n'est pas un jeton"; | |
| 1151 | |
| 1152 net::TestURLFetcherFactory factory; | 1197 net::TestURLFetcherFactory factory; |
| 1153 net::TestURLFetcher* fetcher = NULL; | 1198 net::TestURLFetcher* fetcher = NULL; |
| 1154 scoped_ptr<ServiceForDownloadTests> service( | 1199 scoped_ptr<ServiceForDownloadTests> service( |
| 1155 new ServiceForDownloadTests(prefs_.get())); | 1200 new ServiceForDownloadTests(prefs_.get())); |
| 1156 ExtensionUpdater updater(service.get(), | 1201 const ExtensionDownloader::Factory& downloader_factory = |
| 1157 service->extension_prefs(), | 1202 enable_oauth2 ? service->GetAuthenticatedDownloaderFactory() |
| 1158 service->pref_service(), | 1203 : service->GetDownloaderFactory(); |
| 1159 service->profile(), | 1204 ExtensionUpdater updater( |
| 1160 kUpdateFrequencySecs, | 1205 service.get(), |
| 1161 NULL, | 1206 service->extension_prefs(), |
| 1162 make_scoped_ptr<IdentityProvider>(NULL)); | 1207 service->pref_service(), |
| 1208 service->profile(), | |
| 1209 kUpdateFrequencySecs, | |
| 1210 NULL, | |
| 1211 downloader_factory); | |
| 1163 updater.Start(); | 1212 updater.Start(); |
| 1164 | 1213 updater.EnsureDownloaderCreated(); |
| 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 | |
| 1175 ResetDownloader( | |
| 1176 &updater, | |
| 1177 new ExtensionDownloader(&updater, | |
| 1178 service->request_context(), | |
| 1179 fake_identity_provider.get())); | |
| 1180 updater.downloader_->extensions_queue_.set_backoff_policy( | 1214 updater.downloader_->extensions_queue_.set_backoff_policy( |
| 1181 &kNoBackoffPolicy); | 1215 &kNoBackoffPolicy); |
| 1182 | 1216 |
| 1183 GURL test_url(base::StringPrintf("%s/extension.crx", url_prefix.c_str())); | 1217 GURL test_url(base::StringPrintf("%s/extension.crx", url_prefix.c_str())); |
| 1184 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 1218 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 1185 std::string hash; | 1219 std::string hash; |
| 1186 Version version("0.0.1"); | 1220 Version version("0.0.1"); |
| 1187 std::set<int> requests; | 1221 std::set<int> requests; |
| 1188 requests.insert(0); | 1222 requests.insert(0); |
| 1189 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch( | 1223 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch( |
| 1190 new ExtensionDownloader::ExtensionFetch( | 1224 new ExtensionDownloader::ExtensionFetch( |
| 1191 id, test_url, hash, version.GetString(), requests)); | 1225 id, test_url, hash, version.GetString(), requests)); |
| 1192 updater.downloader_->FetchUpdatedExtension(fetch.Pass()); | 1226 updater.downloader_->FetchUpdatedExtension(fetch.Pass()); |
| 1193 | 1227 |
| 1194 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); | 1228 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); |
| 1195 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1229 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 1196 EXPECT_EQ(kExpectedLoadFlags, fetcher->GetLoadFlags()); | 1230 EXPECT_EQ(kExpectedLoadFlags, fetcher->GetLoadFlags()); |
| 1197 | 1231 |
| 1198 // Fake a 403 response. | 1232 // Fake a 403 response. |
| 1199 fetcher->set_url(test_url); | 1233 fetcher->set_url(test_url); |
| 1200 fetcher->set_status(net::URLRequestStatus()); | 1234 fetcher->set_status(net::URLRequestStatus()); |
| 1201 fetcher->set_response_code(403); | 1235 fetcher->set_response_code(403); |
| 1202 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1236 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 1203 if (fake_token_service) { | 1237 |
| 1204 fake_token_service->IssueAllTokensForAccount( | 1238 if (service->fake_token_service()) { |
| 1239 service->fake_token_service()->IssueAllTokensForAccount( | |
| 1205 kFakeAccountId, kFakeOAuth2Token, base::Time::Now()); | 1240 kFakeAccountId, kFakeOAuth2Token, base::Time::Now()); |
| 1206 } | 1241 } |
| 1207 RunUntilIdle(); | 1242 RunUntilIdle(); |
| 1208 | 1243 |
| 1209 bool using_oauth2 = false; | 1244 bool using_oauth2 = false; |
| 1210 int expected_load_flags = kExpectedLoadFlags; | 1245 int expected_load_flags = kExpectedLoadFlags; |
| 1211 // Verify that the fetch has had its credentials properly incremented. | 1246 // Verify that the fetch has had its credentials properly incremented. |
| 1212 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); | 1247 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); |
| 1213 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1248 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| 1214 net::HttpRequestHeaders fetch_headers; | 1249 net::HttpRequestHeaders fetch_headers; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1346 void TestMultipleExtensionDownloading(bool updates_start_running) { | 1381 void TestMultipleExtensionDownloading(bool updates_start_running) { |
| 1347 net::TestURLFetcherFactory factory; | 1382 net::TestURLFetcherFactory factory; |
| 1348 net::TestURLFetcher* fetcher = NULL; | 1383 net::TestURLFetcher* fetcher = NULL; |
| 1349 ServiceForDownloadTests service(prefs_.get()); | 1384 ServiceForDownloadTests service(prefs_.get()); |
| 1350 ExtensionUpdater updater(&service, | 1385 ExtensionUpdater updater(&service, |
| 1351 service.extension_prefs(), | 1386 service.extension_prefs(), |
| 1352 service.pref_service(), | 1387 service.pref_service(), |
| 1353 service.profile(), | 1388 service.profile(), |
| 1354 kUpdateFrequencySecs, | 1389 kUpdateFrequencySecs, |
| 1355 NULL, | 1390 NULL, |
| 1356 make_scoped_ptr<IdentityProvider>(NULL)); | 1391 service.GetDownloaderFactory()); |
| 1357 updater.Start(); | 1392 updater.Start(); |
| 1358 ResetDownloader( | 1393 updater.EnsureDownloaderCreated(); |
| 1359 &updater, | |
| 1360 new ExtensionDownloader(&updater, service.request_context(), NULL)); | |
| 1361 updater.downloader_->extensions_queue_.set_backoff_policy( | 1394 updater.downloader_->extensions_queue_.set_backoff_policy( |
| 1362 &kNoBackoffPolicy); | 1395 &kNoBackoffPolicy); |
| 1363 | 1396 |
| 1364 EXPECT_FALSE(updater.crx_install_is_running_); | 1397 EXPECT_FALSE(updater.crx_install_is_running_); |
| 1365 | 1398 |
| 1366 GURL url1("http://localhost/extension1.crx"); | 1399 GURL url1("http://localhost/extension1.crx"); |
| 1367 GURL url2("http://localhost/extension2.crx"); | 1400 GURL url2("http://localhost/extension2.crx"); |
| 1368 | 1401 |
| 1369 std::string id1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 1402 std::string id1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 1370 std::string id2 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; | 1403 std::string id2 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1561 } | 1594 } |
| 1562 if (active_bit) | 1595 if (active_bit) |
| 1563 prefs->SetActiveBit(id, true); | 1596 prefs->SetActiveBit(id, true); |
| 1564 | 1597 |
| 1565 ExtensionUpdater updater(&service, | 1598 ExtensionUpdater updater(&service, |
| 1566 service.extension_prefs(), | 1599 service.extension_prefs(), |
| 1567 service.pref_service(), | 1600 service.pref_service(), |
| 1568 service.profile(), | 1601 service.profile(), |
| 1569 kUpdateFrequencySecs, | 1602 kUpdateFrequencySecs, |
| 1570 NULL, | 1603 NULL, |
| 1571 make_scoped_ptr<IdentityProvider>(NULL)); | 1604 service.GetDownloaderFactory()); |
| 1572 ExtensionUpdater::CheckParams params; | 1605 ExtensionUpdater::CheckParams params; |
| 1573 updater.Start(); | 1606 updater.Start(); |
| 1574 updater.CheckNow(params); | 1607 updater.CheckNow(params); |
| 1575 | 1608 |
| 1576 // Make the updater do manifest fetching, and note the urls it tries to | 1609 // Make the updater do manifest fetching, and note the urls it tries to |
| 1577 // fetch. | 1610 // fetch. |
| 1578 std::vector<GURL> fetched_urls; | 1611 std::vector<GURL> fetched_urls; |
| 1579 net::TestURLFetcher* fetcher = | 1612 net::TestURLFetcher* fetcher = |
| 1580 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 1613 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
| 1581 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1614 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1658 service.CreateTestExtensions(1, 1, &tmp, &update_url.spec(), | 1691 service.CreateTestExtensions(1, 1, &tmp, &update_url.spec(), |
| 1659 Manifest::INTERNAL); | 1692 Manifest::INTERNAL); |
| 1660 service.set_extensions(tmp, ExtensionList()); | 1693 service.set_extensions(tmp, ExtensionList()); |
| 1661 | 1694 |
| 1662 ExtensionUpdater updater(&service, | 1695 ExtensionUpdater updater(&service, |
| 1663 service.extension_prefs(), | 1696 service.extension_prefs(), |
| 1664 service.pref_service(), | 1697 service.pref_service(), |
| 1665 service.profile(), | 1698 service.profile(), |
| 1666 kUpdateFrequencySecs, | 1699 kUpdateFrequencySecs, |
| 1667 NULL, | 1700 NULL, |
| 1668 make_scoped_ptr<IdentityProvider>(NULL)); | 1701 service.GetDownloaderFactory()); |
| 1669 updater.Start(); | 1702 updater.Start(); |
| 1670 ResetDownloader( | 1703 updater.EnsureDownloaderCreated(); |
| 1671 &updater, | |
| 1672 new ExtensionDownloader(&updater, service.request_context(), NULL)); | |
| 1673 | 1704 |
| 1674 ManifestFetchData fetch_data(update_url, 0); | 1705 ManifestFetchData fetch_data(update_url, 0); |
| 1675 const Extension* extension = tmp[0].get(); | 1706 const Extension* extension = tmp[0].get(); |
| 1676 fetch_data.AddExtension(extension->id(), | 1707 fetch_data.AddExtension(extension->id(), |
| 1677 extension->VersionString(), | 1708 extension->VersionString(), |
| 1678 &kNeverPingedData, | 1709 &kNeverPingedData, |
| 1679 kEmptyUpdateUrlData, | 1710 kEmptyUpdateUrlData, |
| 1680 std::string()); | 1711 std::string()); |
| 1681 UpdateManifest::Results results; | 1712 UpdateManifest::Results results; |
| 1682 results.daystart_elapsed_seconds = 750; | 1713 results.daystart_elapsed_seconds = 750; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1846 | 1877 |
| 1847 TEST_F(ExtensionUpdaterTest, TestNonAutoUpdateableLocations) { | 1878 TEST_F(ExtensionUpdaterTest, TestNonAutoUpdateableLocations) { |
| 1848 net::TestURLFetcherFactory factory; | 1879 net::TestURLFetcherFactory factory; |
| 1849 ServiceForManifestTests service(prefs_.get()); | 1880 ServiceForManifestTests service(prefs_.get()); |
| 1850 ExtensionUpdater updater(&service, | 1881 ExtensionUpdater updater(&service, |
| 1851 service.extension_prefs(), | 1882 service.extension_prefs(), |
| 1852 service.pref_service(), | 1883 service.pref_service(), |
| 1853 service.profile(), | 1884 service.profile(), |
| 1854 kUpdateFrequencySecs, | 1885 kUpdateFrequencySecs, |
| 1855 NULL, | 1886 NULL, |
| 1856 make_scoped_ptr<IdentityProvider>(NULL)); | 1887 service.GetDownloaderFactory()); |
| 1857 MockExtensionDownloaderDelegate delegate; | 1888 MockExtensionDownloaderDelegate delegate; |
| 1858 // Set the downloader directly, so that all its events end up in the mock | 1889 service.OverrideDownloaderDelegate(&delegate); |
| 1859 // |delegate|. | |
| 1860 ExtensionDownloader* downloader = | |
| 1861 new ExtensionDownloader(&delegate, service.request_context(), NULL); | |
| 1862 ResetDownloader(&updater, downloader); | |
| 1863 | 1890 |
| 1864 // Non-internal non-external extensions should be rejected. | 1891 // Non-internal non-external extensions should be rejected. |
| 1865 ExtensionList extensions; | 1892 ExtensionList extensions; |
| 1866 service.CreateTestExtensions(1, 1, &extensions, NULL, | 1893 service.CreateTestExtensions(1, 1, &extensions, NULL, |
| 1867 Manifest::INVALID_LOCATION); | 1894 Manifest::INVALID_LOCATION); |
| 1868 service.CreateTestExtensions(2, 1, &extensions, NULL, Manifest::INTERNAL); | 1895 service.CreateTestExtensions(2, 1, &extensions, NULL, Manifest::INTERNAL); |
| 1869 ASSERT_EQ(2u, extensions.size()); | 1896 ASSERT_EQ(2u, extensions.size()); |
| 1870 const std::string& updateable_id = extensions[1]->id(); | 1897 const std::string& updateable_id = extensions[1]->id(); |
| 1871 | 1898 |
| 1872 // These expectations fail if the delegate's methods are invoked for the | 1899 // These expectations fail if the delegate's methods are invoked for the |
| 1873 // first extension, which has a non-matching id. | 1900 // first extension, which has a non-matching id. |
| 1874 EXPECT_CALL(delegate, GetUpdateUrlData(updateable_id)).WillOnce(Return("")); | 1901 EXPECT_CALL(delegate, |
| 1902 GetUpdateUrlData(updateable_id)).WillOnce(Return("")); | |
| 1875 EXPECT_CALL(delegate, GetPingDataForExtension(updateable_id, _)); | 1903 EXPECT_CALL(delegate, GetPingDataForExtension(updateable_id, _)); |
| 1876 | 1904 |
| 1877 service.set_extensions(extensions, ExtensionList()); | 1905 service.set_extensions(extensions, ExtensionList()); |
| 1878 ExtensionUpdater::CheckParams params; | 1906 ExtensionUpdater::CheckParams params; |
| 1879 updater.Start(); | 1907 updater.Start(); |
| 1880 updater.CheckNow(params); | 1908 updater.CheckNow(params); |
| 1881 } | 1909 } |
| 1882 | 1910 |
| 1883 TEST_F(ExtensionUpdaterTest, TestUpdatingDisabledExtensions) { | 1911 TEST_F(ExtensionUpdaterTest, TestUpdatingDisabledExtensions) { |
| 1884 net::TestURLFetcherFactory factory; | 1912 net::TestURLFetcherFactory factory; |
| 1885 ServiceForManifestTests service(prefs_.get()); | 1913 ServiceForManifestTests service(prefs_.get()); |
| 1886 ExtensionUpdater updater(&service, | 1914 ExtensionUpdater updater(&service, |
| 1887 service.extension_prefs(), | 1915 service.extension_prefs(), |
| 1888 service.pref_service(), | 1916 service.pref_service(), |
| 1889 service.profile(), | 1917 service.profile(), |
| 1890 kUpdateFrequencySecs, | 1918 kUpdateFrequencySecs, |
| 1891 NULL, | 1919 NULL, |
| 1892 make_scoped_ptr<IdentityProvider>(NULL)); | 1920 service.GetDownloaderFactory()); |
| 1893 MockExtensionDownloaderDelegate delegate; | 1921 MockExtensionDownloaderDelegate delegate; |
| 1894 // Set the downloader directly, so that all its events end up in the mock | 1922 service.OverrideDownloaderDelegate(&delegate); |
| 1895 // |delegate|. | |
| 1896 ExtensionDownloader* downloader = | |
| 1897 new ExtensionDownloader(&delegate, service.request_context(), NULL); | |
| 1898 ResetDownloader(&updater, downloader); | |
| 1899 | 1923 |
| 1900 // Non-internal non-external extensions should be rejected. | 1924 // Non-internal non-external extensions should be rejected. |
| 1901 ExtensionList enabled_extensions; | 1925 ExtensionList enabled_extensions; |
| 1902 ExtensionList disabled_extensions; | 1926 ExtensionList disabled_extensions; |
| 1903 service.CreateTestExtensions(1, 1, &enabled_extensions, NULL, | 1927 service.CreateTestExtensions(1, 1, &enabled_extensions, NULL, |
| 1904 Manifest::INTERNAL); | 1928 Manifest::INTERNAL); |
| 1905 service.CreateTestExtensions(2, 1, &disabled_extensions, NULL, | 1929 service.CreateTestExtensions(2, 1, &disabled_extensions, NULL, |
| 1906 Manifest::INTERNAL); | 1930 Manifest::INTERNAL); |
| 1907 ASSERT_EQ(1u, enabled_extensions.size()); | 1931 ASSERT_EQ(1u, enabled_extensions.size()); |
| 1908 ASSERT_EQ(1u, disabled_extensions.size()); | 1932 ASSERT_EQ(1u, disabled_extensions.size()); |
| 1909 const std::string& enabled_id = enabled_extensions[0]->id(); | 1933 const std::string& enabled_id = enabled_extensions[0]->id(); |
| 1910 const std::string& disabled_id = disabled_extensions[0]->id(); | 1934 const std::string& disabled_id = disabled_extensions[0]->id(); |
| 1911 | 1935 |
| 1912 // We expect that both enabled and disabled extensions are auto-updated. | 1936 // We expect that both enabled and disabled extensions are auto-updated. |
| 1913 EXPECT_CALL(delegate, GetUpdateUrlData(enabled_id)).WillOnce(Return("")); | 1937 EXPECT_CALL(delegate, GetUpdateUrlData(enabled_id)).WillOnce(Return("")); |
| 1914 EXPECT_CALL(delegate, GetPingDataForExtension(enabled_id, _)); | 1938 EXPECT_CALL(delegate, GetPingDataForExtension(enabled_id, _)); |
| 1915 EXPECT_CALL(delegate, GetUpdateUrlData(disabled_id)).WillOnce(Return("")); | 1939 EXPECT_CALL(delegate, |
| 1940 GetUpdateUrlData(disabled_id)).WillOnce(Return("")); | |
| 1916 EXPECT_CALL(delegate, GetPingDataForExtension(disabled_id, _)); | 1941 EXPECT_CALL(delegate, GetPingDataForExtension(disabled_id, _)); |
| 1917 | 1942 |
| 1918 service.set_extensions(enabled_extensions, disabled_extensions); | 1943 service.set_extensions(enabled_extensions, disabled_extensions); |
| 1919 ExtensionUpdater::CheckParams params; | 1944 ExtensionUpdater::CheckParams params; |
| 1920 updater.Start(); | 1945 updater.Start(); |
| 1921 updater.CheckNow(params); | 1946 updater.CheckNow(params); |
| 1922 } | 1947 } |
| 1923 | 1948 |
| 1924 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { | 1949 TEST_F(ExtensionUpdaterTest, TestManifestFetchesBuilderAddExtension) { |
| 1925 net::TestURLFetcherFactory factory; | 1950 net::TestURLFetcherFactory factory; |
| 1926 MockService service(prefs_.get()); | 1951 MockService service(prefs_.get()); |
| 1927 MockExtensionDownloaderDelegate delegate; | 1952 MockExtensionDownloaderDelegate delegate; |
| 1928 scoped_ptr<ExtensionDownloader> downloader( | 1953 scoped_ptr<ExtensionDownloader> downloader( |
| 1929 new ExtensionDownloader(&delegate, service.request_context(), NULL)); | 1954 new ExtensionDownloader(&delegate, service.request_context())); |
| 1930 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); | 1955 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); |
| 1931 | 1956 |
| 1932 // First, verify that adding valid extensions does invoke the callbacks on | 1957 // First, verify that adding valid extensions does invoke the callbacks on |
| 1933 // the delegate. | 1958 // the delegate. |
| 1934 std::string id = id_util::GenerateId("foo"); | 1959 std::string id = id_util::GenerateId("foo"); |
| 1935 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); | 1960 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); |
| 1936 EXPECT_TRUE( | 1961 EXPECT_TRUE( |
| 1937 downloader->AddPendingExtension(id, GURL("http://example.com/update"), | 1962 downloader->AddPendingExtension(id, GURL("http://example.com/update"), |
| 1938 0)); | 1963 0)); |
| 1939 downloader->StartAllPending(NULL); | 1964 downloader->StartAllPending(NULL); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1950 // Extensions with empty IDs should be rejected. | 1975 // Extensions with empty IDs should be rejected. |
| 1951 EXPECT_FALSE(downloader->AddPendingExtension(std::string(), GURL(), 0)); | 1976 EXPECT_FALSE(downloader->AddPendingExtension(std::string(), GURL(), 0)); |
| 1952 downloader->StartAllPending(NULL); | 1977 downloader->StartAllPending(NULL); |
| 1953 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); | 1978 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
| 1954 | 1979 |
| 1955 // TODO(akalin): Test that extensions with empty update URLs | 1980 // TODO(akalin): Test that extensions with empty update URLs |
| 1956 // converted from user scripts are rejected. | 1981 // converted from user scripts are rejected. |
| 1957 | 1982 |
| 1958 // Reset the ExtensionDownloader so that it drops the current fetcher. | 1983 // Reset the ExtensionDownloader so that it drops the current fetcher. |
| 1959 downloader.reset( | 1984 downloader.reset( |
| 1960 new ExtensionDownloader(&delegate, service.request_context(), NULL)); | 1985 new ExtensionDownloader(&delegate, service.request_context())); |
| 1961 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); | 1986 EXPECT_EQ(0u, ManifestFetchersCount(downloader.get())); |
| 1962 | 1987 |
| 1963 // Extensions with empty update URLs should have a default one | 1988 // Extensions with empty update URLs should have a default one |
| 1964 // filled in. | 1989 // filled in. |
| 1965 id = id_util::GenerateId("foo3"); | 1990 id = id_util::GenerateId("foo3"); |
| 1966 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); | 1991 EXPECT_CALL(delegate, GetPingDataForExtension(id, _)).WillOnce(Return(false)); |
| 1967 EXPECT_TRUE(downloader->AddPendingExtension(id, GURL(), 0)); | 1992 EXPECT_TRUE(downloader->AddPendingExtension(id, GURL(), 0)); |
| 1968 downloader->StartAllPending(NULL); | 1993 downloader->StartAllPending(NULL); |
| 1969 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); | 1994 EXPECT_EQ(1u, ManifestFetchersCount(downloader.get())); |
| 1970 | 1995 |
| 1971 net::TestURLFetcher* fetcher = | 1996 net::TestURLFetcher* fetcher = |
| 1972 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 1997 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
| 1973 ASSERT_TRUE(fetcher); | 1998 ASSERT_TRUE(fetcher); |
| 1974 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); | 1999 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); |
| 1975 } | 2000 } |
| 1976 | 2001 |
| 1977 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { | 2002 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { |
| 1978 net::TestURLFetcherFactory factory; | 2003 net::TestURLFetcherFactory factory; |
| 1979 MockService service(prefs_.get()); | 2004 MockService service(prefs_.get()); |
| 1980 MockExtensionDownloaderDelegate delegate; | 2005 MockExtensionDownloaderDelegate delegate; |
| 1981 ExtensionDownloader downloader(&delegate, service.request_context(), NULL); | 2006 ExtensionDownloader downloader(&delegate, service.request_context()); |
| 1982 | 2007 |
| 1983 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0)); | 2008 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0)); |
| 1984 // This should delete the newly-created ManifestFetchData. | 2009 // This should delete the newly-created ManifestFetchData. |
| 1985 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0)); | 2010 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0)); |
| 1986 // This should add into |manifests_pending_|. | 2011 // This should add into |manifests_pending_|. |
| 1987 StartUpdateCheck(&downloader, new ManifestFetchData(GURL( | 2012 StartUpdateCheck(&downloader, new ManifestFetchData(GURL( |
| 1988 GURL("http://www.google.com")), 0)); | 2013 GURL("http://www.google.com")), 0)); |
| 1989 // The dtor of |downloader| should delete the pending fetchers. | 2014 // The dtor of |downloader| should delete the pending fetchers. |
| 1990 } | 2015 } |
| 1991 | 2016 |
| 1992 TEST_F(ExtensionUpdaterTest, TestCheckSoon) { | 2017 TEST_F(ExtensionUpdaterTest, TestCheckSoon) { |
| 1993 ServiceForManifestTests service(prefs_.get()); | 2018 ServiceForManifestTests service(prefs_.get()); |
| 1994 net::TestURLFetcherFactory factory; | 2019 net::TestURLFetcherFactory factory; |
| 1995 ExtensionUpdater updater(&service, | 2020 ExtensionUpdater updater(&service, |
| 1996 service.extension_prefs(), | 2021 service.extension_prefs(), |
| 1997 service.pref_service(), | 2022 service.pref_service(), |
| 1998 service.profile(), | 2023 service.profile(), |
| 1999 kUpdateFrequencySecs, | 2024 kUpdateFrequencySecs, |
| 2000 NULL, | 2025 NULL, |
| 2001 make_scoped_ptr<IdentityProvider>(NULL)); | 2026 service.GetDownloaderFactory()); |
| 2002 EXPECT_FALSE(updater.WillCheckSoon()); | 2027 EXPECT_FALSE(updater.WillCheckSoon()); |
| 2003 updater.Start(); | 2028 updater.Start(); |
| 2004 EXPECT_FALSE(updater.WillCheckSoon()); | 2029 EXPECT_FALSE(updater.WillCheckSoon()); |
| 2005 updater.CheckSoon(); | 2030 updater.CheckSoon(); |
| 2006 EXPECT_TRUE(updater.WillCheckSoon()); | 2031 EXPECT_TRUE(updater.WillCheckSoon()); |
| 2007 updater.CheckSoon(); | 2032 updater.CheckSoon(); |
| 2008 EXPECT_TRUE(updater.WillCheckSoon()); | 2033 EXPECT_TRUE(updater.WillCheckSoon()); |
| 2009 RunUntilIdle(); | 2034 RunUntilIdle(); |
| 2010 EXPECT_FALSE(updater.WillCheckSoon()); | 2035 EXPECT_FALSE(updater.WillCheckSoon()); |
| 2011 updater.CheckSoon(); | 2036 updater.CheckSoon(); |
| 2012 EXPECT_TRUE(updater.WillCheckSoon()); | 2037 EXPECT_TRUE(updater.WillCheckSoon()); |
| 2013 updater.Stop(); | 2038 updater.Stop(); |
| 2014 EXPECT_FALSE(updater.WillCheckSoon()); | 2039 EXPECT_FALSE(updater.WillCheckSoon()); |
| 2015 } | 2040 } |
| 2016 | 2041 |
| 2017 // TODO(asargent) - (http://crbug.com/12780) add tests for: | 2042 // TODO(asargent) - (http://crbug.com/12780) add tests for: |
| 2018 // -prodversionmin (shouldn't update if browser version too old) | 2043 // -prodversionmin (shouldn't update if browser version too old) |
| 2019 // -manifests & updates arriving out of order / interleaved | 2044 // -manifests & updates arriving out of order / interleaved |
| 2020 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 2045 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
| 2021 // -An extension gets uninstalled while updates are in progress (so it doesn't | 2046 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 2022 // "come back from the dead") | 2047 // "come back from the dead") |
| 2023 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 2048 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 2024 // you don't get downgraded accidentally) | 2049 // you don't get downgraded accidentally) |
| 2025 // -An update manifest mentions multiple updates | 2050 // -An update manifest mentions multiple updates |
| 2026 | 2051 |
| 2027 } // namespace extensions | 2052 } // namespace extensions |
| OLD | NEW |