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 12 matching lines...) Expand all Loading... |
23 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
24 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
25 #include "base/version.h" | 25 #include "base/version.h" |
26 #include "chrome/browser/chrome_notification_types.h" | 26 #include "chrome/browser/chrome_notification_types.h" |
27 #include "chrome/browser/extensions/crx_installer.h" | 27 #include "chrome/browser/extensions/crx_installer.h" |
28 #include "chrome/browser/extensions/extension_error_reporter.h" | 28 #include "chrome/browser/extensions/extension_error_reporter.h" |
29 #include "chrome/browser/extensions/extension_sync_data.h" | 29 #include "chrome/browser/extensions/extension_sync_data.h" |
30 #include "chrome/browser/extensions/test_extension_prefs.h" | 30 #include "chrome/browser/extensions/test_extension_prefs.h" |
31 #include "chrome/browser/extensions/test_extension_service.h" | 31 #include "chrome/browser/extensions/test_extension_service.h" |
32 #include "chrome/browser/extensions/test_extension_system.h" | 32 #include "chrome/browser/extensions/test_extension_system.h" |
| 33 #include "chrome/browser/extensions/updater/chrome_extension_downloader_factory.
h" |
33 #include "chrome/browser/extensions/updater/extension_downloader.h" | 34 #include "chrome/browser/extensions/updater/extension_downloader.h" |
34 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h" | 35 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h" |
35 #include "chrome/browser/extensions/updater/extension_updater.h" | 36 #include "chrome/browser/extensions/updater/extension_updater.h" |
36 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" | |
37 #include "chrome/browser/extensions/updater/request_queue_impl.h" | 37 #include "chrome/browser/extensions/updater/request_queue_impl.h" |
38 #include "chrome/browser/google/google_brand.h" | 38 #include "chrome/browser/google/google_brand.h" |
39 #include "chrome/browser/prefs/pref_service_syncable.h" | 39 #include "chrome/browser/prefs/pref_service_syncable.h" |
40 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
41 #include "chrome/test/base/testing_profile.h" | 41 #include "chrome/test/base/testing_profile.h" |
42 #include "components/crx_file/id_util.h" | 42 #include "components/crx_file/id_util.h" |
43 #include "components/omaha_query_params/omaha_query_params.h" | 43 #include "components/omaha_query_params/omaha_query_params.h" |
44 #include "content/public/browser/notification_details.h" | 44 #include "content/public/browser/notification_details.h" |
45 #include "content/public/browser/notification_observer.h" | 45 #include "content/public/browser/notification_observer.h" |
46 #include "content/public/browser/notification_registrar.h" | 46 #include "content/public/browser/notification_registrar.h" |
47 #include "content/public/browser/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
48 #include "content/public/browser/notification_source.h" | 48 #include "content/public/browser/notification_source.h" |
49 #include "content/public/test/test_browser_thread_bundle.h" | 49 #include "content/public/test/test_browser_thread_bundle.h" |
50 #include "content/public/test/test_utils.h" | 50 #include "content/public/test/test_utils.h" |
51 #include "extensions/browser/extension_prefs.h" | 51 #include "extensions/browser/extension_prefs.h" |
52 #include "extensions/browser/extension_registry.h" | 52 #include "extensions/browser/extension_registry.h" |
53 #include "extensions/browser/extension_system.h" | 53 #include "extensions/browser/extension_system.h" |
| 54 #include "extensions/browser/updater/manifest_fetch_data.h" |
54 #include "extensions/common/extension.h" | 55 #include "extensions/common/extension.h" |
55 #include "extensions/common/manifest_constants.h" | 56 #include "extensions/common/manifest_constants.h" |
56 #include "google_apis/gaia/fake_identity_provider.h" | 57 #include "google_apis/gaia/fake_identity_provider.h" |
57 #include "google_apis/gaia/fake_oauth2_token_service.h" | 58 #include "google_apis/gaia/fake_oauth2_token_service.h" |
58 #include "libxml/globals.h" | 59 #include "libxml/globals.h" |
59 #include "net/base/backoff_entry.h" | 60 #include "net/base/backoff_entry.h" |
60 #include "net/base/escape.h" | 61 #include "net/base/escape.h" |
61 #include "net/base/load_flags.h" | 62 #include "net/base/load_flags.h" |
62 #include "net/http/http_request_headers.h" | 63 #include "net/http/http_request_headers.h" |
63 #include "net/url_request/test_url_fetcher_factory.h" | 64 #include "net/url_request/test_url_fetcher_factory.h" |
64 #include "net/url_request/url_request_status.h" | 65 #include "net/url_request/url_request_status.h" |
65 #include "testing/gmock/include/gmock/gmock.h" | 66 #include "testing/gmock/include/gmock/gmock.h" |
66 #include "testing/gtest/include/gtest/gtest.h" | 67 #include "testing/gtest/include/gtest/gtest.h" |
67 #include "url/third_party/mozilla/url_parse.h" | 68 #include "url/third_party/mozilla/url_parse.h" |
68 | 69 |
69 #if defined(OS_CHROMEOS) | 70 #if defined(OS_CHROMEOS) |
70 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" | 71 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" |
71 #include "chrome/browser/chromeos/settings/cros_settings.h" | 72 #include "chrome/browser/chromeos/settings/cros_settings.h" |
72 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 73 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
73 #endif | 74 #endif |
74 | 75 |
75 using base::Time; | 76 using base::Time; |
76 using base::TimeDelta; | 77 using base::TimeDelta; |
77 using content::BrowserThread; | 78 using content::BrowserThread; |
| 79 using omaha_query_params::OmahaQueryParams; |
78 using testing::DoAll; | 80 using testing::DoAll; |
79 using testing::Invoke; | 81 using testing::Invoke; |
80 using testing::InvokeWithoutArgs; | 82 using testing::InvokeWithoutArgs; |
81 using testing::Mock; | 83 using testing::Mock; |
82 using testing::Return; | 84 using testing::Return; |
83 using testing::SetArgPointee; | 85 using testing::SetArgPointee; |
84 using testing::_; | 86 using testing::_; |
85 | 87 |
86 namespace extensions { | 88 namespace extensions { |
87 | 89 |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 } | 351 } |
350 | 352 |
351 protected: | 353 protected: |
352 TestExtensionPrefs* const prefs_; | 354 TestExtensionPrefs* const prefs_; |
353 TestingProfile profile_; | 355 TestingProfile profile_; |
354 PendingExtensionManager pending_extension_manager_; | 356 PendingExtensionManager pending_extension_manager_; |
355 | 357 |
356 private: | 358 private: |
357 scoped_ptr<ExtensionDownloader> CreateExtensionDownloader( | 359 scoped_ptr<ExtensionDownloader> CreateExtensionDownloader( |
358 ExtensionDownloaderDelegate* delegate) { | 360 ExtensionDownloaderDelegate* delegate) { |
359 return make_scoped_ptr(new ExtensionDownloader( | 361 return ChromeExtensionDownloaderFactory::CreateForRequestContext( |
| 362 request_context(), |
360 downloader_delegate_override_ ? downloader_delegate_override_ | 363 downloader_delegate_override_ ? downloader_delegate_override_ |
361 : delegate, | 364 : delegate); |
362 request_context())); | |
363 } | 365 } |
364 | 366 |
365 scoped_ptr<ExtensionDownloader> CreateExtensionDownloaderWithIdentity( | 367 scoped_ptr<ExtensionDownloader> CreateExtensionDownloaderWithIdentity( |
366 ExtensionDownloaderDelegate* delegate) { | 368 ExtensionDownloaderDelegate* delegate) { |
367 scoped_ptr<FakeIdentityProvider> fake_identity_provider; | 369 scoped_ptr<FakeIdentityProvider> fake_identity_provider; |
368 fake_token_service_.reset(new FakeOAuth2TokenService()); | 370 fake_token_service_.reset(new FakeOAuth2TokenService()); |
369 fake_identity_provider.reset(new FakeIdentityProvider( | 371 fake_identity_provider.reset(new FakeIdentityProvider( |
370 fake_token_service_.get())); | 372 fake_token_service_.get())); |
371 fake_identity_provider->LogIn(kFakeAccountId); | 373 fake_identity_provider->LogIn(kFakeAccountId); |
372 fake_token_service_->AddAccount(kFakeAccountId); | 374 fake_token_service_->AddAccount(kFakeAccountId); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 } | 562 } |
561 } | 563 } |
562 } | 564 } |
563 | 565 |
564 static void VerifyQueryAndExtractParameters( | 566 static void VerifyQueryAndExtractParameters( |
565 const std::string& query, | 567 const std::string& query, |
566 std::map<std::string, std::string>* result) { | 568 std::map<std::string, std::string>* result) { |
567 std::map<std::string, std::string> params; | 569 std::map<std::string, std::string> params; |
568 ExtractParameters(query, ¶ms); | 570 ExtractParameters(query, ¶ms); |
569 | 571 |
570 std::string omaha_params = omaha_query_params::OmahaQueryParams::Get( | 572 std::string omaha_params = OmahaQueryParams::Get(OmahaQueryParams::CRX); |
571 omaha_query_params::OmahaQueryParams::CRX); | |
572 std::map<std::string, std::string> expected; | 573 std::map<std::string, std::string> expected; |
573 ExtractParameters(omaha_params, &expected); | 574 ExtractParameters(omaha_params, &expected); |
574 | 575 |
575 for (std::map<std::string, std::string>::iterator it = expected.begin(); | 576 for (std::map<std::string, std::string>::iterator it = expected.begin(); |
576 it != expected.end(); ++it) { | 577 it != expected.end(); ++it) { |
577 EXPECT_EQ(it->second, params[it->first]); | 578 EXPECT_EQ(it->second, params[it->first]); |
578 } | 579 } |
579 | 580 |
580 EXPECT_EQ(1U, params.count("x")); | 581 EXPECT_EQ(1U, params.count("x")); |
581 std::string decoded = net::UnescapeURLComponent( | 582 std::string decoded = net::UnescapeURLComponent( |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 } | 696 } |
696 EXPECT_EQ("", params["uc"]); | 697 EXPECT_EQ("", params["uc"]); |
697 } | 698 } |
698 | 699 |
699 void TestUpdateUrlDataEmpty() { | 700 void TestUpdateUrlDataEmpty() { |
700 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 701 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
701 const std::string version = "1.0"; | 702 const std::string version = "1.0"; |
702 | 703 |
703 // Make sure that an empty update URL data string does not cause a ap= | 704 // Make sure that an empty update URL data string does not cause a ap= |
704 // option to appear in the x= parameter. | 705 // option to appear in the x= parameter. |
705 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 706 scoped_ptr<ManifestFetchData> fetch_data( |
706 fetch_data.AddExtension( | 707 CreateManifestFetchData(GURL("http://localhost/foo"))); |
| 708 fetch_data->AddExtension( |
707 id, version, &kNeverPingedData, std::string(), std::string(), false); | 709 id, version, &kNeverPingedData, std::string(), std::string(), false); |
708 | 710 |
709 std::map<std::string, std::string> params; | 711 std::map<std::string, std::string> params; |
710 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 712 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
711 EXPECT_EQ(id, params["id"]); | 713 EXPECT_EQ(id, params["id"]); |
712 EXPECT_EQ(version, params["v"]); | 714 EXPECT_EQ(version, params["v"]); |
713 EXPECT_EQ(0U, params.count("ap")); | 715 EXPECT_EQ(0U, params.count("ap")); |
714 } | 716 } |
715 | 717 |
716 void TestUpdateUrlDataSimple() { | 718 void TestUpdateUrlDataSimple() { |
717 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 719 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
718 const std::string version = "1.0"; | 720 const std::string version = "1.0"; |
719 | 721 |
720 // Make sure that an update URL data string causes an appropriate ap= | 722 // Make sure that an update URL data string causes an appropriate ap= |
721 // option to appear in the x= parameter. | 723 // option to appear in the x= parameter. |
722 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 724 scoped_ptr<ManifestFetchData> fetch_data( |
723 fetch_data.AddExtension( | 725 CreateManifestFetchData(GURL("http://localhost/foo"))); |
| 726 fetch_data->AddExtension( |
724 id, version, &kNeverPingedData, "bar", std::string(), false); | 727 id, version, &kNeverPingedData, "bar", std::string(), false); |
725 std::map<std::string, std::string> params; | 728 std::map<std::string, std::string> params; |
726 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 729 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
727 EXPECT_EQ(id, params["id"]); | 730 EXPECT_EQ(id, params["id"]); |
728 EXPECT_EQ(version, params["v"]); | 731 EXPECT_EQ(version, params["v"]); |
729 EXPECT_EQ("bar", params["ap"]); | 732 EXPECT_EQ("bar", params["ap"]); |
730 } | 733 } |
731 | 734 |
732 void TestUpdateUrlDataCompound() { | 735 void TestUpdateUrlDataCompound() { |
733 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 736 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
734 const std::string version = "1.0"; | 737 const std::string version = "1.0"; |
735 | 738 |
736 // Make sure that an update URL data string causes an appropriate ap= | 739 // Make sure that an update URL data string causes an appropriate ap= |
737 // option to appear in the x= parameter. | 740 // option to appear in the x= parameter. |
738 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 741 scoped_ptr<ManifestFetchData> fetch_data( |
739 fetch_data.AddExtension( | 742 CreateManifestFetchData(GURL("http://localhost/foo"))); |
| 743 fetch_data->AddExtension( |
740 id, version, &kNeverPingedData, "a=1&b=2&c", std::string(), false); | 744 id, version, &kNeverPingedData, "a=1&b=2&c", std::string(), false); |
741 std::map<std::string, std::string> params; | 745 std::map<std::string, std::string> params; |
742 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 746 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
743 EXPECT_EQ(id, params["id"]); | 747 EXPECT_EQ(id, params["id"]); |
744 EXPECT_EQ(version, params["v"]); | 748 EXPECT_EQ(version, params["v"]); |
745 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); | 749 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); |
746 } | 750 } |
747 | 751 |
748 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { | 752 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { |
749 net::TestURLFetcherFactory factory; | 753 net::TestURLFetcherFactory factory; |
750 | 754 |
751 MockService service(prefs_.get()); | 755 MockService service(prefs_.get()); |
752 MockExtensionDownloaderDelegate delegate; | 756 MockExtensionDownloaderDelegate delegate; |
(...skipping 19 matching lines...) Expand all Loading... |
772 std::string::size_type ap = update_url.find("ap%3D", x); | 776 std::string::size_type ap = update_url.find("ap%3D", x); |
773 EXPECT_EQ(std::string::npos, ap); | 777 EXPECT_EQ(std::string::npos, ap); |
774 } | 778 } |
775 | 779 |
776 void TestInstallSource() { | 780 void TestInstallSource() { |
777 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 781 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
778 const std::string version = "1.0"; | 782 const std::string version = "1.0"; |
779 const std::string install_source = "instally"; | 783 const std::string install_source = "instally"; |
780 | 784 |
781 // Make sure that an installsource= appears in the x= parameter. | 785 // Make sure that an installsource= appears in the x= parameter. |
782 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 786 scoped_ptr<ManifestFetchData> fetch_data( |
783 fetch_data.AddExtension(id, version, &kNeverPingedData, | 787 CreateManifestFetchData(GURL("http://localhost/foo"))); |
784 kEmptyUpdateUrlData, install_source, false); | 788 fetch_data->AddExtension(id, version, &kNeverPingedData, |
| 789 kEmptyUpdateUrlData, install_source, false); |
785 std::map<std::string, std::string> params; | 790 std::map<std::string, std::string> params; |
786 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 791 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
787 EXPECT_EQ(id, params["id"]); | 792 EXPECT_EQ(id, params["id"]); |
788 EXPECT_EQ(version, params["v"]); | 793 EXPECT_EQ(version, params["v"]); |
789 EXPECT_EQ(install_source, params["installsource"]); | 794 EXPECT_EQ(install_source, params["installsource"]); |
790 } | 795 } |
791 | 796 |
792 void TestDetermineUpdates() { | 797 void TestDetermineUpdates() { |
793 TestingProfile profile; | 798 TestingProfile profile; |
794 MockExtensionDownloaderDelegate delegate; | 799 MockExtensionDownloaderDelegate delegate; |
795 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); | 800 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); |
796 | 801 |
797 // Check passing an empty list of parse results to DetermineUpdates | 802 // Check passing an empty list of parse results to DetermineUpdates |
798 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 803 scoped_ptr<ManifestFetchData> fetch_data( |
| 804 CreateManifestFetchData(GURL("http://localhost/foo"))); |
799 UpdateManifest::Results updates; | 805 UpdateManifest::Results updates; |
800 std::vector<int> updateable; | 806 std::vector<int> updateable; |
801 downloader.DetermineUpdates(fetch_data, updates, &updateable); | 807 downloader.DetermineUpdates(*fetch_data, updates, &updateable); |
802 EXPECT_TRUE(updateable.empty()); | 808 EXPECT_TRUE(updateable.empty()); |
803 | 809 |
804 // Create two updates - expect that DetermineUpdates will return the first | 810 // Create two updates - expect that DetermineUpdates will return the first |
805 // one (v1.0 installed, v1.1 available) but not the second one (both | 811 // one (v1.0 installed, v1.1 available) but not the second one (both |
806 // installed and available at v2.0). | 812 // installed and available at v2.0). |
807 const std::string id1 = crx_file::id_util::GenerateId("1"); | 813 const std::string id1 = crx_file::id_util::GenerateId("1"); |
808 const std::string id2 = crx_file::id_util::GenerateId("2"); | 814 const std::string id2 = crx_file::id_util::GenerateId("2"); |
809 fetch_data.AddExtension( | 815 fetch_data->AddExtension( |
810 id1, "1.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string(), | 816 id1, "1.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string(), |
811 false); | 817 false); |
812 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates); | 818 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates); |
813 fetch_data.AddExtension( | 819 fetch_data->AddExtension( |
814 id2, "2.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string(), | 820 id2, "2.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string(), |
815 false); | 821 false); |
816 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates); | 822 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates); |
817 | 823 |
818 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); | 824 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); |
819 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _)) | 825 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _)) |
820 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"), | 826 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"), |
821 Return(true))); | 827 Return(true))); |
822 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _)) | 828 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _)) |
823 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), | 829 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), |
824 Return(true))); | 830 Return(true))); |
825 | 831 |
826 downloader.DetermineUpdates(fetch_data, updates, &updateable); | 832 downloader.DetermineUpdates(*fetch_data, updates, &updateable); |
827 EXPECT_EQ(1u, updateable.size()); | 833 EXPECT_EQ(1u, updateable.size()); |
828 EXPECT_EQ(0, updateable[0]); | 834 EXPECT_EQ(0, updateable[0]); |
829 } | 835 } |
830 | 836 |
831 void TestDetermineUpdatesPending() { | 837 void TestDetermineUpdatesPending() { |
832 // Create a set of test extensions | 838 // Create a set of test extensions |
833 ServiceForManifestTests service(prefs_.get()); | 839 ServiceForManifestTests service(prefs_.get()); |
834 PendingExtensionManager* pending_extension_manager = | 840 PendingExtensionManager* pending_extension_manager = |
835 service.pending_extension_manager(); | 841 service.pending_extension_manager(); |
836 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); | 842 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); |
837 | 843 |
838 TestingProfile profile; | 844 TestingProfile profile; |
839 MockExtensionDownloaderDelegate delegate; | 845 MockExtensionDownloaderDelegate delegate; |
840 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); | 846 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); |
841 | 847 |
842 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 848 scoped_ptr<ManifestFetchData> fetch_data( |
| 849 CreateManifestFetchData(GURL("http://localhost/foo"))); |
843 UpdateManifest::Results updates; | 850 UpdateManifest::Results updates; |
844 | 851 |
845 std::list<std::string> ids_for_update_check; | 852 std::list<std::string> ids_for_update_check; |
846 pending_extension_manager->GetPendingIdsForUpdateCheck( | 853 pending_extension_manager->GetPendingIdsForUpdateCheck( |
847 &ids_for_update_check); | 854 &ids_for_update_check); |
848 | 855 |
849 std::list<std::string>::const_iterator it; | 856 std::list<std::string>::const_iterator it; |
850 for (it = ids_for_update_check.begin(); | 857 for (it = ids_for_update_check.begin(); |
851 it != ids_for_update_check.end(); ++it) { | 858 it != ids_for_update_check.end(); ++it) { |
852 fetch_data.AddExtension(*it, | 859 fetch_data->AddExtension(*it, |
853 "1.0.0.0", | 860 "1.0.0.0", |
854 &kNeverPingedData, | 861 &kNeverPingedData, |
855 kEmptyUpdateUrlData, | 862 kEmptyUpdateUrlData, |
856 std::string(), | 863 std::string(), |
857 false); | 864 false); |
858 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); | 865 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); |
859 } | 866 } |
860 | 867 |
861 // The delegate will tell the downloader that all the extensions are | 868 // The delegate will tell the downloader that all the extensions are |
862 // pending. | 869 // pending. |
863 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true)); | 870 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true)); |
864 | 871 |
865 std::vector<int> updateable; | 872 std::vector<int> updateable; |
866 downloader.DetermineUpdates(fetch_data, updates, &updateable); | 873 downloader.DetermineUpdates(*fetch_data, updates, &updateable); |
867 // All the apps should be updateable. | 874 // All the apps should be updateable. |
868 EXPECT_EQ(3u, updateable.size()); | 875 EXPECT_EQ(3u, updateable.size()); |
869 for (std::vector<int>::size_type i = 0; i < updateable.size(); ++i) { | 876 for (std::vector<int>::size_type i = 0; i < updateable.size(); ++i) { |
870 EXPECT_EQ(static_cast<int>(i), updateable[i]); | 877 EXPECT_EQ(static_cast<int>(i), updateable[i]); |
871 } | 878 } |
872 } | 879 } |
873 | 880 |
874 void TestMultipleManifestDownloading() { | 881 void TestMultipleManifestDownloading() { |
875 net::TestURLFetcherFactory factory; | 882 net::TestURLFetcherFactory factory; |
876 factory.set_remove_fetcher_on_delete(true); | 883 factory.set_remove_fetcher_on_delete(true); |
877 net::TestURLFetcher* fetcher = NULL; | 884 net::TestURLFetcher* fetcher = NULL; |
878 MockService service(prefs_.get()); | 885 MockService service(prefs_.get()); |
879 MockExtensionDownloaderDelegate delegate; | 886 MockExtensionDownloaderDelegate delegate; |
880 ExtensionDownloader downloader(&delegate, service.request_context()); | 887 ExtensionDownloader downloader(&delegate, service.request_context()); |
881 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); | 888 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); |
882 | 889 |
883 GURL kUpdateUrl("http://localhost/manifest1"); | 890 GURL kUpdateUrl("http://localhost/manifest1"); |
884 | 891 |
885 scoped_ptr<ManifestFetchData> fetch1(new ManifestFetchData(kUpdateUrl, 0)); | 892 scoped_ptr<ManifestFetchData> fetch1(CreateManifestFetchData(kUpdateUrl)); |
886 scoped_ptr<ManifestFetchData> fetch2(new ManifestFetchData(kUpdateUrl, 0)); | 893 scoped_ptr<ManifestFetchData> fetch2(CreateManifestFetchData(kUpdateUrl)); |
887 scoped_ptr<ManifestFetchData> fetch3(new ManifestFetchData(kUpdateUrl, 0)); | 894 scoped_ptr<ManifestFetchData> fetch3(CreateManifestFetchData(kUpdateUrl)); |
888 scoped_ptr<ManifestFetchData> fetch4(new ManifestFetchData(kUpdateUrl, 0)); | 895 scoped_ptr<ManifestFetchData> fetch4(CreateManifestFetchData(kUpdateUrl)); |
889 ManifestFetchData::PingData zeroDays(0, 0, true); | 896 ManifestFetchData::PingData zeroDays(0, 0, true); |
890 fetch1->AddExtension( | 897 fetch1->AddExtension( |
891 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); | 898 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); |
892 fetch2->AddExtension( | 899 fetch2->AddExtension( |
893 "2222", "2.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); | 900 "2222", "2.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); |
894 fetch3->AddExtension( | 901 fetch3->AddExtension( |
895 "3333", "3.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); | 902 "3333", "3.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); |
896 fetch4->AddExtension( | 903 fetch4->AddExtension( |
897 "4444", "4.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); | 904 "4444", "4.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); |
898 | 905 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 net::TestURLFetcherFactory factory; | 1022 net::TestURLFetcherFactory factory; |
1016 net::TestURLFetcher* fetcher = NULL; | 1023 net::TestURLFetcher* fetcher = NULL; |
1017 NotificationsObserver observer; | 1024 NotificationsObserver observer; |
1018 MockService service(prefs_.get()); | 1025 MockService service(prefs_.get()); |
1019 MockExtensionDownloaderDelegate delegate; | 1026 MockExtensionDownloaderDelegate delegate; |
1020 ExtensionDownloader downloader(&delegate, service.request_context()); | 1027 ExtensionDownloader downloader(&delegate, service.request_context()); |
1021 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); | 1028 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); |
1022 | 1029 |
1023 GURL kUpdateUrl("http://localhost/manifest1"); | 1030 GURL kUpdateUrl("http://localhost/manifest1"); |
1024 | 1031 |
1025 scoped_ptr<ManifestFetchData> fetch(new ManifestFetchData(kUpdateUrl, 0)); | 1032 scoped_ptr<ManifestFetchData> fetch(CreateManifestFetchData(kUpdateUrl)); |
1026 ManifestFetchData::PingData zeroDays(0, 0, true); | 1033 ManifestFetchData::PingData zeroDays(0, 0, true); |
1027 fetch->AddExtension( | 1034 fetch->AddExtension( |
1028 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); | 1035 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); |
1029 | 1036 |
1030 // This will start the first fetcher. | 1037 // This will start the first fetcher. |
1031 downloader.StartUpdateCheck(fetch.Pass()); | 1038 downloader.StartUpdateCheck(fetch.Pass()); |
1032 RunUntilIdle(); | 1039 RunUntilIdle(); |
1033 | 1040 |
1034 // ExtensionDownloader should retry kMaxRetries times and then fail. | 1041 // ExtensionDownloader should retry kMaxRetries times and then fail. |
1035 EXPECT_CALL(delegate, OnExtensionDownloadFailed( | 1042 EXPECT_CALL(delegate, OnExtensionDownloadFailed( |
1036 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); | 1043 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); |
1037 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) { | 1044 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) { |
1038 // All fetches will fail. | 1045 // All fetches will fail. |
1039 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 1046 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
1040 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1047 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
1041 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 1048 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
1042 fetcher->set_url(kUpdateUrl); | 1049 fetcher->set_url(kUpdateUrl); |
1043 fetcher->set_status(net::URLRequestStatus()); | 1050 fetcher->set_status(net::URLRequestStatus()); |
1044 // Code 5xx causes ExtensionDownloader to retry. | 1051 // Code 5xx causes ExtensionDownloader to retry. |
1045 fetcher->set_response_code(500); | 1052 fetcher->set_response_code(500); |
1046 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1053 fetcher->delegate()->OnURLFetchComplete(fetcher); |
1047 RunUntilIdle(); | 1054 RunUntilIdle(); |
1048 } | 1055 } |
1049 Mock::VerifyAndClearExpectations(&delegate); | 1056 Mock::VerifyAndClearExpectations(&delegate); |
1050 | 1057 |
1051 | 1058 |
1052 // For response codes that are not in the 5xx range ExtensionDownloader | 1059 // For response codes that are not in the 5xx range ExtensionDownloader |
1053 // should not retry. | 1060 // should not retry. |
1054 fetch.reset(new ManifestFetchData(kUpdateUrl, 0)); | 1061 fetch.reset(CreateManifestFetchData(kUpdateUrl)); |
1055 fetch->AddExtension( | 1062 fetch->AddExtension( |
1056 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); | 1063 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string(), false); |
1057 | 1064 |
1058 // This will start the first fetcher. | 1065 // This will start the first fetcher. |
1059 downloader.StartUpdateCheck(fetch.Pass()); | 1066 downloader.StartUpdateCheck(fetch.Pass()); |
1060 RunUntilIdle(); | 1067 RunUntilIdle(); |
1061 | 1068 |
1062 EXPECT_CALL(delegate, OnExtensionDownloadFailed( | 1069 EXPECT_CALL(delegate, OnExtensionDownloadFailed( |
1063 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); | 1070 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); |
1064 // The first fetch will fail, and require retrying. | 1071 // The first fetch will fail, and require retrying. |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1699 ExtensionUpdater updater(&service, | 1706 ExtensionUpdater updater(&service, |
1700 service.extension_prefs(), | 1707 service.extension_prefs(), |
1701 service.pref_service(), | 1708 service.pref_service(), |
1702 service.profile(), | 1709 service.profile(), |
1703 kUpdateFrequencySecs, | 1710 kUpdateFrequencySecs, |
1704 NULL, | 1711 NULL, |
1705 service.GetDownloaderFactory()); | 1712 service.GetDownloaderFactory()); |
1706 updater.Start(); | 1713 updater.Start(); |
1707 updater.EnsureDownloaderCreated(); | 1714 updater.EnsureDownloaderCreated(); |
1708 | 1715 |
1709 ManifestFetchData fetch_data(update_url, 0); | 1716 scoped_ptr<ManifestFetchData> fetch_data( |
| 1717 CreateManifestFetchData(update_url)); |
1710 const Extension* extension = tmp[0].get(); | 1718 const Extension* extension = tmp[0].get(); |
1711 fetch_data.AddExtension(extension->id(), | 1719 fetch_data->AddExtension(extension->id(), |
1712 extension->VersionString(), | 1720 extension->VersionString(), |
1713 &kNeverPingedData, | 1721 &kNeverPingedData, |
1714 kEmptyUpdateUrlData, | 1722 kEmptyUpdateUrlData, |
1715 std::string(), | 1723 std::string(), |
1716 false); | 1724 false); |
1717 UpdateManifest::Results results; | 1725 UpdateManifest::Results results; |
1718 results.daystart_elapsed_seconds = 750; | 1726 results.daystart_elapsed_seconds = 750; |
1719 | 1727 |
1720 updater.downloader_->HandleManifestResults(fetch_data, &results); | 1728 updater.downloader_->HandleManifestResults(*fetch_data, &results); |
1721 Time last_ping_day = | 1729 Time last_ping_day = |
1722 service.extension_prefs()->LastPingDay(extension->id()); | 1730 service.extension_prefs()->LastPingDay(extension->id()); |
1723 EXPECT_FALSE(last_ping_day.is_null()); | 1731 EXPECT_FALSE(last_ping_day.is_null()); |
1724 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds(); | 1732 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds(); |
1725 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); | 1733 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); |
1726 } | 1734 } |
1727 | 1735 |
1728 protected: | 1736 protected: |
1729 scoped_ptr<TestExtensionPrefs> prefs_; | 1737 scoped_ptr<TestExtensionPrefs> prefs_; |
1730 | 1738 |
| 1739 ManifestFetchData* CreateManifestFetchData(const GURL& update_url) { |
| 1740 return new ManifestFetchData(update_url, |
| 1741 0, |
| 1742 "", |
| 1743 OmahaQueryParams::Get(OmahaQueryParams::CRX), |
| 1744 ManifestFetchData::PING); |
| 1745 } |
| 1746 |
1731 private: | 1747 private: |
1732 content::TestBrowserThreadBundle thread_bundle_; | 1748 content::TestBrowserThreadBundle thread_bundle_; |
1733 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; | 1749 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; |
1734 | 1750 |
1735 #if defined OS_CHROMEOS | 1751 #if defined OS_CHROMEOS |
1736 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 1752 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
1737 chromeos::ScopedTestCrosSettings test_cros_settings_; | 1753 chromeos::ScopedTestCrosSettings test_cros_settings_; |
1738 chromeos::ScopedTestUserManager test_user_manager_; | 1754 chromeos::ScopedTestUserManager test_user_manager_; |
1739 #endif | 1755 #endif |
1740 }; | 1756 }; |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2005 ASSERT_TRUE(fetcher); | 2021 ASSERT_TRUE(fetcher); |
2006 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); | 2022 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); |
2007 } | 2023 } |
2008 | 2024 |
2009 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { | 2025 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { |
2010 net::TestURLFetcherFactory factory; | 2026 net::TestURLFetcherFactory factory; |
2011 MockService service(prefs_.get()); | 2027 MockService service(prefs_.get()); |
2012 MockExtensionDownloaderDelegate delegate; | 2028 MockExtensionDownloaderDelegate delegate; |
2013 ExtensionDownloader downloader(&delegate, service.request_context()); | 2029 ExtensionDownloader downloader(&delegate, service.request_context()); |
2014 | 2030 |
2015 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0)); | 2031 StartUpdateCheck(&downloader, CreateManifestFetchData(GURL())); |
2016 // This should delete the newly-created ManifestFetchData. | 2032 // This should delete the newly-created ManifestFetchData. |
2017 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0)); | 2033 StartUpdateCheck(&downloader, CreateManifestFetchData(GURL())); |
2018 // This should add into |manifests_pending_|. | 2034 // This should add into |manifests_pending_|. |
2019 StartUpdateCheck(&downloader, new ManifestFetchData(GURL( | 2035 StartUpdateCheck(&downloader, |
2020 GURL("http://www.google.com")), 0)); | 2036 CreateManifestFetchData(GURL("http://www.google.com"))); |
2021 // The dtor of |downloader| should delete the pending fetchers. | 2037 // The dtor of |downloader| should delete the pending fetchers. |
2022 } | 2038 } |
2023 | 2039 |
2024 TEST_F(ExtensionUpdaterTest, TestCheckSoon) { | 2040 TEST_F(ExtensionUpdaterTest, TestCheckSoon) { |
2025 ServiceForManifestTests service(prefs_.get()); | 2041 ServiceForManifestTests service(prefs_.get()); |
2026 net::TestURLFetcherFactory factory; | 2042 net::TestURLFetcherFactory factory; |
2027 ExtensionUpdater updater(&service, | 2043 ExtensionUpdater updater(&service, |
2028 service.extension_prefs(), | 2044 service.extension_prefs(), |
2029 service.pref_service(), | 2045 service.pref_service(), |
2030 service.profile(), | 2046 service.profile(), |
(...skipping 19 matching lines...) Expand all Loading... |
2050 // -prodversionmin (shouldn't update if browser version too old) | 2066 // -prodversionmin (shouldn't update if browser version too old) |
2051 // -manifests & updates arriving out of order / interleaved | 2067 // -manifests & updates arriving out of order / interleaved |
2052 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 2068 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
2053 // -An extension gets uninstalled while updates are in progress (so it doesn't | 2069 // -An extension gets uninstalled while updates are in progress (so it doesn't |
2054 // "come back from the dead") | 2070 // "come back from the dead") |
2055 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 2071 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
2056 // you don't get downgraded accidentally) | 2072 // you don't get downgraded accidentally) |
2057 // -An update manifest mentions multiple updates | 2073 // -An update manifest mentions multiple updates |
2058 | 2074 |
2059 } // namespace extensions | 2075 } // namespace extensions |
OLD | NEW |