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