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/omaha_query_params/omaha_query_params.h" | 42 #include "components/omaha_query_params/omaha_query_params.h" |
43 #include "content/public/browser/notification_details.h" | 43 #include "content/public/browser/notification_details.h" |
44 #include "content/public/browser/notification_observer.h" | 44 #include "content/public/browser/notification_observer.h" |
45 #include "content/public/browser/notification_registrar.h" | 45 #include "content/public/browser/notification_registrar.h" |
46 #include "content/public/browser/notification_service.h" | 46 #include "content/public/browser/notification_service.h" |
47 #include "content/public/browser/notification_source.h" | 47 #include "content/public/browser/notification_source.h" |
48 #include "content/public/test/test_browser_thread_bundle.h" | 48 #include "content/public/test/test_browser_thread_bundle.h" |
49 #include "content/public/test/test_utils.h" | 49 #include "content/public/test/test_utils.h" |
50 #include "extensions/browser/extension_prefs.h" | 50 #include "extensions/browser/extension_prefs.h" |
51 #include "extensions/browser/extension_registry.h" | 51 #include "extensions/browser/extension_registry.h" |
52 #include "extensions/browser/extension_system.h" | 52 #include "extensions/browser/extension_system.h" |
| 53 #include "extensions/browser/updater/manifest_fetch_data.h" |
53 #include "extensions/common/extension.h" | 54 #include "extensions/common/extension.h" |
54 #include "extensions/common/id_util.h" | 55 #include "extensions/common/id_util.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/user_manager.h" | 71 #include "chrome/browser/chromeos/login/users/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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 } | 561 } |
560 } | 562 } |
561 } | 563 } |
562 | 564 |
563 static void VerifyQueryAndExtractParameters( | 565 static void VerifyQueryAndExtractParameters( |
564 const std::string& query, | 566 const std::string& query, |
565 std::map<std::string, std::string>* result) { | 567 std::map<std::string, std::string>* result) { |
566 std::map<std::string, std::string> params; | 568 std::map<std::string, std::string> params; |
567 ExtractParameters(query, ¶ms); | 569 ExtractParameters(query, ¶ms); |
568 | 570 |
569 std::string omaha_params = omaha_query_params::OmahaQueryParams::Get( | 571 std::string omaha_params = OmahaQueryParams::Get(OmahaQueryParams::CRX); |
570 omaha_query_params::OmahaQueryParams::CRX); | |
571 std::map<std::string, std::string> expected; | 572 std::map<std::string, std::string> expected; |
572 ExtractParameters(omaha_params, &expected); | 573 ExtractParameters(omaha_params, &expected); |
573 | 574 |
574 for (std::map<std::string, std::string>::iterator it = expected.begin(); | 575 for (std::map<std::string, std::string>::iterator it = expected.begin(); |
575 it != expected.end(); ++it) { | 576 it != expected.end(); ++it) { |
576 EXPECT_EQ(it->second, params[it->first]); | 577 EXPECT_EQ(it->second, params[it->first]); |
577 } | 578 } |
578 | 579 |
579 EXPECT_EQ(1U, params.count("x")); | 580 EXPECT_EQ(1U, params.count("x")); |
580 std::string decoded = net::UnescapeURLComponent( | 581 std::string decoded = net::UnescapeURLComponent( |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 } | 694 } |
694 EXPECT_EQ("", params["uc"]); | 695 EXPECT_EQ("", params["uc"]); |
695 } | 696 } |
696 | 697 |
697 void TestUpdateUrlDataEmpty() { | 698 void TestUpdateUrlDataEmpty() { |
698 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 699 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
699 const std::string version = "1.0"; | 700 const std::string version = "1.0"; |
700 | 701 |
701 // Make sure that an empty update URL data string does not cause a ap= | 702 // Make sure that an empty update URL data string does not cause a ap= |
702 // option to appear in the x= parameter. | 703 // option to appear in the x= parameter. |
703 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 704 scoped_ptr<ManifestFetchData> fetch_data( |
704 fetch_data.AddExtension( | 705 CreateManifestFetchData(GURL("http://localhost/foo"))); |
| 706 fetch_data->AddExtension( |
705 id, version, &kNeverPingedData, std::string(), std::string()); | 707 id, version, &kNeverPingedData, std::string(), std::string()); |
706 | 708 |
707 std::map<std::string, std::string> params; | 709 std::map<std::string, std::string> params; |
708 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 710 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
709 EXPECT_EQ(id, params["id"]); | 711 EXPECT_EQ(id, params["id"]); |
710 EXPECT_EQ(version, params["v"]); | 712 EXPECT_EQ(version, params["v"]); |
711 EXPECT_EQ(0U, params.count("ap")); | 713 EXPECT_EQ(0U, params.count("ap")); |
712 } | 714 } |
713 | 715 |
714 void TestUpdateUrlDataSimple() { | 716 void TestUpdateUrlDataSimple() { |
715 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 717 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
716 const std::string version = "1.0"; | 718 const std::string version = "1.0"; |
717 | 719 |
718 // Make sure that an update URL data string causes an appropriate ap= | 720 // Make sure that an update URL data string causes an appropriate ap= |
719 // option to appear in the x= parameter. | 721 // option to appear in the x= parameter. |
720 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 722 scoped_ptr<ManifestFetchData> fetch_data( |
721 fetch_data.AddExtension( | 723 CreateManifestFetchData(GURL("http://localhost/foo"))); |
| 724 fetch_data->AddExtension( |
722 id, version, &kNeverPingedData, "bar", std::string()); | 725 id, version, &kNeverPingedData, "bar", std::string()); |
723 std::map<std::string, std::string> params; | 726 std::map<std::string, std::string> params; |
724 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 727 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
725 EXPECT_EQ(id, params["id"]); | 728 EXPECT_EQ(id, params["id"]); |
726 EXPECT_EQ(version, params["v"]); | 729 EXPECT_EQ(version, params["v"]); |
727 EXPECT_EQ("bar", params["ap"]); | 730 EXPECT_EQ("bar", params["ap"]); |
728 } | 731 } |
729 | 732 |
730 void TestUpdateUrlDataCompound() { | 733 void TestUpdateUrlDataCompound() { |
731 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 734 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
732 const std::string version = "1.0"; | 735 const std::string version = "1.0"; |
733 | 736 |
734 // Make sure that an update URL data string causes an appropriate ap= | 737 // Make sure that an update URL data string causes an appropriate ap= |
735 // option to appear in the x= parameter. | 738 // option to appear in the x= parameter. |
736 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 739 scoped_ptr<ManifestFetchData> fetch_data( |
737 fetch_data.AddExtension( | 740 CreateManifestFetchData(GURL("http://localhost/foo"))); |
| 741 fetch_data->AddExtension( |
738 id, version, &kNeverPingedData, "a=1&b=2&c", std::string()); | 742 id, version, &kNeverPingedData, "a=1&b=2&c", std::string()); |
739 std::map<std::string, std::string> params; | 743 std::map<std::string, std::string> params; |
740 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 744 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
741 EXPECT_EQ(id, params["id"]); | 745 EXPECT_EQ(id, params["id"]); |
742 EXPECT_EQ(version, params["v"]); | 746 EXPECT_EQ(version, params["v"]); |
743 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); | 747 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); |
744 } | 748 } |
745 | 749 |
746 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { | 750 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { |
747 net::TestURLFetcherFactory factory; | 751 net::TestURLFetcherFactory factory; |
748 | 752 |
749 MockService service(prefs_.get()); | 753 MockService service(prefs_.get()); |
750 MockExtensionDownloaderDelegate delegate; | 754 MockExtensionDownloaderDelegate delegate; |
(...skipping 19 matching lines...) Expand all Loading... |
770 std::string::size_type ap = update_url.find("ap%3D", x); | 774 std::string::size_type ap = update_url.find("ap%3D", x); |
771 EXPECT_EQ(std::string::npos, ap); | 775 EXPECT_EQ(std::string::npos, ap); |
772 } | 776 } |
773 | 777 |
774 void TestInstallSource() { | 778 void TestInstallSource() { |
775 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 779 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
776 const std::string version = "1.0"; | 780 const std::string version = "1.0"; |
777 const std::string install_source = "instally"; | 781 const std::string install_source = "instally"; |
778 | 782 |
779 // Make sure that an installsource= appears in the x= parameter. | 783 // Make sure that an installsource= appears in the x= parameter. |
780 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 784 scoped_ptr<ManifestFetchData> fetch_data( |
781 fetch_data.AddExtension(id, version, &kNeverPingedData, | 785 CreateManifestFetchData(GURL("http://localhost/foo"))); |
782 kEmptyUpdateUrlData, install_source); | 786 fetch_data->AddExtension( |
| 787 id, version, &kNeverPingedData, kEmptyUpdateUrlData, install_source); |
783 std::map<std::string, std::string> params; | 788 std::map<std::string, std::string> params; |
784 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); | 789 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), ¶ms); |
785 EXPECT_EQ(id, params["id"]); | 790 EXPECT_EQ(id, params["id"]); |
786 EXPECT_EQ(version, params["v"]); | 791 EXPECT_EQ(version, params["v"]); |
787 EXPECT_EQ(install_source, params["installsource"]); | 792 EXPECT_EQ(install_source, params["installsource"]); |
788 } | 793 } |
789 | 794 |
790 void TestDetermineUpdates() { | 795 void TestDetermineUpdates() { |
791 TestingProfile profile; | 796 TestingProfile profile; |
792 MockExtensionDownloaderDelegate delegate; | 797 MockExtensionDownloaderDelegate delegate; |
793 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); | 798 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); |
794 | 799 |
795 // Check passing an empty list of parse results to DetermineUpdates | 800 // Check passing an empty list of parse results to DetermineUpdates |
796 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 801 scoped_ptr<ManifestFetchData> fetch_data( |
| 802 CreateManifestFetchData(GURL("http://localhost/foo"))); |
797 UpdateManifest::Results updates; | 803 UpdateManifest::Results updates; |
798 std::vector<int> updateable; | 804 std::vector<int> updateable; |
799 downloader.DetermineUpdates(fetch_data, updates, &updateable); | 805 downloader.DetermineUpdates(*fetch_data, updates, &updateable); |
800 EXPECT_TRUE(updateable.empty()); | 806 EXPECT_TRUE(updateable.empty()); |
801 | 807 |
802 // Create two updates - expect that DetermineUpdates will return the first | 808 // Create two updates - expect that DetermineUpdates will return the first |
803 // one (v1.0 installed, v1.1 available) but not the second one (both | 809 // one (v1.0 installed, v1.1 available) but not the second one (both |
804 // installed and available at v2.0). | 810 // installed and available at v2.0). |
805 const std::string id1 = id_util::GenerateId("1"); | 811 const std::string id1 = id_util::GenerateId("1"); |
806 const std::string id2 = id_util::GenerateId("2"); | 812 const std::string id2 = id_util::GenerateId("2"); |
807 fetch_data.AddExtension( | 813 fetch_data->AddExtension( |
808 id1, "1.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string()); | 814 id1, "1.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string()); |
809 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates); | 815 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates); |
810 fetch_data.AddExtension( | 816 fetch_data->AddExtension( |
811 id2, "2.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string()); | 817 id2, "2.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string()); |
812 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates); | 818 AddParseResult(id2, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates); |
813 | 819 |
814 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); | 820 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); |
815 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _)) | 821 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _)) |
816 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"), | 822 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"), |
817 Return(true))); | 823 Return(true))); |
818 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _)) | 824 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _)) |
819 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), | 825 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), |
820 Return(true))); | 826 Return(true))); |
821 | 827 |
822 downloader.DetermineUpdates(fetch_data, updates, &updateable); | 828 downloader.DetermineUpdates(*fetch_data, updates, &updateable); |
823 EXPECT_EQ(1u, updateable.size()); | 829 EXPECT_EQ(1u, updateable.size()); |
824 EXPECT_EQ(0, updateable[0]); | 830 EXPECT_EQ(0, updateable[0]); |
825 } | 831 } |
826 | 832 |
827 void TestDetermineUpdatesPending() { | 833 void TestDetermineUpdatesPending() { |
828 // Create a set of test extensions | 834 // Create a set of test extensions |
829 ServiceForManifestTests service(prefs_.get()); | 835 ServiceForManifestTests service(prefs_.get()); |
830 PendingExtensionManager* pending_extension_manager = | 836 PendingExtensionManager* pending_extension_manager = |
831 service.pending_extension_manager(); | 837 service.pending_extension_manager(); |
832 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); | 838 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); |
833 | 839 |
834 TestingProfile profile; | 840 TestingProfile profile; |
835 MockExtensionDownloaderDelegate delegate; | 841 MockExtensionDownloaderDelegate delegate; |
836 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); | 842 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); |
837 | 843 |
838 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 844 scoped_ptr<ManifestFetchData> fetch_data( |
| 845 CreateManifestFetchData(GURL("http://localhost/foo"))); |
839 UpdateManifest::Results updates; | 846 UpdateManifest::Results updates; |
840 | 847 |
841 std::list<std::string> ids_for_update_check; | 848 std::list<std::string> ids_for_update_check; |
842 pending_extension_manager->GetPendingIdsForUpdateCheck( | 849 pending_extension_manager->GetPendingIdsForUpdateCheck( |
843 &ids_for_update_check); | 850 &ids_for_update_check); |
844 | 851 |
845 std::list<std::string>::const_iterator it; | 852 std::list<std::string>::const_iterator it; |
846 for (it = ids_for_update_check.begin(); | 853 for (it = ids_for_update_check.begin(); |
847 it != ids_for_update_check.end(); ++it) { | 854 it != ids_for_update_check.end(); ++it) { |
848 fetch_data.AddExtension(*it, | 855 fetch_data->AddExtension(*it, |
849 "1.0.0.0", | 856 "1.0.0.0", |
850 &kNeverPingedData, | 857 &kNeverPingedData, |
851 kEmptyUpdateUrlData, | 858 kEmptyUpdateUrlData, |
852 std::string()); | 859 std::string()); |
853 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); | 860 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); |
854 } | 861 } |
855 | 862 |
856 // The delegate will tell the downloader that all the extensions are | 863 // The delegate will tell the downloader that all the extensions are |
857 // pending. | 864 // pending. |
858 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true)); | 865 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true)); |
859 | 866 |
860 std::vector<int> updateable; | 867 std::vector<int> updateable; |
861 downloader.DetermineUpdates(fetch_data, updates, &updateable); | 868 downloader.DetermineUpdates(*fetch_data, updates, &updateable); |
862 // All the apps should be updateable. | 869 // All the apps should be updateable. |
863 EXPECT_EQ(3u, updateable.size()); | 870 EXPECT_EQ(3u, updateable.size()); |
864 for (std::vector<int>::size_type i = 0; i < updateable.size(); ++i) { | 871 for (std::vector<int>::size_type i = 0; i < updateable.size(); ++i) { |
865 EXPECT_EQ(static_cast<int>(i), updateable[i]); | 872 EXPECT_EQ(static_cast<int>(i), updateable[i]); |
866 } | 873 } |
867 } | 874 } |
868 | 875 |
869 void TestMultipleManifestDownloading() { | 876 void TestMultipleManifestDownloading() { |
870 net::TestURLFetcherFactory factory; | 877 net::TestURLFetcherFactory factory; |
871 factory.set_remove_fetcher_on_delete(true); | 878 factory.set_remove_fetcher_on_delete(true); |
872 net::TestURLFetcher* fetcher = NULL; | 879 net::TestURLFetcher* fetcher = NULL; |
873 MockService service(prefs_.get()); | 880 MockService service(prefs_.get()); |
874 MockExtensionDownloaderDelegate delegate; | 881 MockExtensionDownloaderDelegate delegate; |
875 ExtensionDownloader downloader(&delegate, service.request_context()); | 882 ExtensionDownloader downloader(&delegate, service.request_context()); |
876 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); | 883 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); |
877 | 884 |
878 GURL kUpdateUrl("http://localhost/manifest1"); | 885 GURL kUpdateUrl("http://localhost/manifest1"); |
879 | 886 |
880 scoped_ptr<ManifestFetchData> fetch1(new ManifestFetchData(kUpdateUrl, 0)); | 887 scoped_ptr<ManifestFetchData> fetch1(CreateManifestFetchData(kUpdateUrl)); |
881 scoped_ptr<ManifestFetchData> fetch2(new ManifestFetchData(kUpdateUrl, 0)); | 888 scoped_ptr<ManifestFetchData> fetch2(CreateManifestFetchData(kUpdateUrl)); |
882 scoped_ptr<ManifestFetchData> fetch3(new ManifestFetchData(kUpdateUrl, 0)); | 889 scoped_ptr<ManifestFetchData> fetch3(CreateManifestFetchData(kUpdateUrl)); |
883 scoped_ptr<ManifestFetchData> fetch4(new ManifestFetchData(kUpdateUrl, 0)); | 890 scoped_ptr<ManifestFetchData> fetch4(CreateManifestFetchData(kUpdateUrl)); |
884 ManifestFetchData::PingData zeroDays(0, 0, true); | 891 ManifestFetchData::PingData zeroDays(0, 0, true); |
885 fetch1->AddExtension( | 892 fetch1->AddExtension( |
886 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 893 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); |
887 fetch2->AddExtension( | 894 fetch2->AddExtension( |
888 "2222", "2.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 895 "2222", "2.0", &zeroDays, kEmptyUpdateUrlData, std::string()); |
889 fetch3->AddExtension( | 896 fetch3->AddExtension( |
890 "3333", "3.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 897 "3333", "3.0", &zeroDays, kEmptyUpdateUrlData, std::string()); |
891 fetch4->AddExtension( | 898 fetch4->AddExtension( |
892 "4444", "4.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 899 "4444", "4.0", &zeroDays, kEmptyUpdateUrlData, std::string()); |
893 | 900 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 net::TestURLFetcherFactory factory; | 1017 net::TestURLFetcherFactory factory; |
1011 net::TestURLFetcher* fetcher = NULL; | 1018 net::TestURLFetcher* fetcher = NULL; |
1012 NotificationsObserver observer; | 1019 NotificationsObserver observer; |
1013 MockService service(prefs_.get()); | 1020 MockService service(prefs_.get()); |
1014 MockExtensionDownloaderDelegate delegate; | 1021 MockExtensionDownloaderDelegate delegate; |
1015 ExtensionDownloader downloader(&delegate, service.request_context()); | 1022 ExtensionDownloader downloader(&delegate, service.request_context()); |
1016 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); | 1023 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); |
1017 | 1024 |
1018 GURL kUpdateUrl("http://localhost/manifest1"); | 1025 GURL kUpdateUrl("http://localhost/manifest1"); |
1019 | 1026 |
1020 scoped_ptr<ManifestFetchData> fetch(new ManifestFetchData(kUpdateUrl, 0)); | 1027 scoped_ptr<ManifestFetchData> fetch(CreateManifestFetchData(kUpdateUrl)); |
1021 ManifestFetchData::PingData zeroDays(0, 0, true); | 1028 ManifestFetchData::PingData zeroDays(0, 0, true); |
1022 fetch->AddExtension( | 1029 fetch->AddExtension( |
1023 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 1030 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); |
1024 | 1031 |
1025 // This will start the first fetcher. | 1032 // This will start the first fetcher. |
1026 downloader.StartUpdateCheck(fetch.Pass()); | 1033 downloader.StartUpdateCheck(fetch.Pass()); |
1027 RunUntilIdle(); | 1034 RunUntilIdle(); |
1028 | 1035 |
1029 // ExtensionDownloader should retry kMaxRetries times and then fail. | 1036 // ExtensionDownloader should retry kMaxRetries times and then fail. |
1030 EXPECT_CALL(delegate, OnExtensionDownloadFailed( | 1037 EXPECT_CALL(delegate, OnExtensionDownloadFailed( |
1031 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); | 1038 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); |
1032 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) { | 1039 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) { |
1033 // All fetches will fail. | 1040 // All fetches will fail. |
1034 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 1041 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
1035 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); | 1042 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
1036 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); | 1043 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
1037 fetcher->set_url(kUpdateUrl); | 1044 fetcher->set_url(kUpdateUrl); |
1038 fetcher->set_status(net::URLRequestStatus()); | 1045 fetcher->set_status(net::URLRequestStatus()); |
1039 // Code 5xx causes ExtensionDownloader to retry. | 1046 // Code 5xx causes ExtensionDownloader to retry. |
1040 fetcher->set_response_code(500); | 1047 fetcher->set_response_code(500); |
1041 fetcher->delegate()->OnURLFetchComplete(fetcher); | 1048 fetcher->delegate()->OnURLFetchComplete(fetcher); |
1042 RunUntilIdle(); | 1049 RunUntilIdle(); |
1043 } | 1050 } |
1044 Mock::VerifyAndClearExpectations(&delegate); | 1051 Mock::VerifyAndClearExpectations(&delegate); |
1045 | 1052 |
1046 | 1053 |
1047 // For response codes that are not in the 5xx range ExtensionDownloader | 1054 // For response codes that are not in the 5xx range ExtensionDownloader |
1048 // should not retry. | 1055 // should not retry. |
1049 fetch.reset(new ManifestFetchData(kUpdateUrl, 0)); | 1056 fetch.reset(CreateManifestFetchData(kUpdateUrl)); |
1050 fetch->AddExtension( | 1057 fetch->AddExtension( |
1051 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); | 1058 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); |
1052 | 1059 |
1053 // This will start the first fetcher. | 1060 // This will start the first fetcher. |
1054 downloader.StartUpdateCheck(fetch.Pass()); | 1061 downloader.StartUpdateCheck(fetch.Pass()); |
1055 RunUntilIdle(); | 1062 RunUntilIdle(); |
1056 | 1063 |
1057 EXPECT_CALL(delegate, OnExtensionDownloadFailed( | 1064 EXPECT_CALL(delegate, OnExtensionDownloadFailed( |
1058 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); | 1065 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); |
1059 // The first fetch will fail, and require retrying. | 1066 // The first fetch will fail, and require retrying. |
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1693 ExtensionUpdater updater(&service, | 1700 ExtensionUpdater updater(&service, |
1694 service.extension_prefs(), | 1701 service.extension_prefs(), |
1695 service.pref_service(), | 1702 service.pref_service(), |
1696 service.profile(), | 1703 service.profile(), |
1697 kUpdateFrequencySecs, | 1704 kUpdateFrequencySecs, |
1698 NULL, | 1705 NULL, |
1699 service.GetDownloaderFactory()); | 1706 service.GetDownloaderFactory()); |
1700 updater.Start(); | 1707 updater.Start(); |
1701 updater.EnsureDownloaderCreated(); | 1708 updater.EnsureDownloaderCreated(); |
1702 | 1709 |
1703 ManifestFetchData fetch_data(update_url, 0); | 1710 scoped_ptr<ManifestFetchData> fetch_data( |
| 1711 CreateManifestFetchData(update_url)); |
1704 const Extension* extension = tmp[0].get(); | 1712 const Extension* extension = tmp[0].get(); |
1705 fetch_data.AddExtension(extension->id(), | 1713 fetch_data->AddExtension(extension->id(), |
1706 extension->VersionString(), | 1714 extension->VersionString(), |
1707 &kNeverPingedData, | 1715 &kNeverPingedData, |
1708 kEmptyUpdateUrlData, | 1716 kEmptyUpdateUrlData, |
1709 std::string()); | 1717 std::string()); |
1710 UpdateManifest::Results results; | 1718 UpdateManifest::Results results; |
1711 results.daystart_elapsed_seconds = 750; | 1719 results.daystart_elapsed_seconds = 750; |
1712 | 1720 |
1713 updater.downloader_->HandleManifestResults(fetch_data, &results); | 1721 updater.downloader_->HandleManifestResults(*fetch_data, &results); |
1714 Time last_ping_day = | 1722 Time last_ping_day = |
1715 service.extension_prefs()->LastPingDay(extension->id()); | 1723 service.extension_prefs()->LastPingDay(extension->id()); |
1716 EXPECT_FALSE(last_ping_day.is_null()); | 1724 EXPECT_FALSE(last_ping_day.is_null()); |
1717 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds(); | 1725 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds(); |
1718 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); | 1726 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); |
1719 } | 1727 } |
1720 | 1728 |
1721 protected: | 1729 protected: |
1722 scoped_ptr<TestExtensionPrefs> prefs_; | 1730 scoped_ptr<TestExtensionPrefs> prefs_; |
1723 | 1731 |
| 1732 ManifestFetchData* CreateManifestFetchData(const GURL& update_url) { |
| 1733 return new ManifestFetchData(update_url, |
| 1734 0, |
| 1735 "", |
| 1736 OmahaQueryParams::Get(OmahaQueryParams::CRX), |
| 1737 ManifestFetchData::PING); |
| 1738 } |
| 1739 |
1724 private: | 1740 private: |
1725 content::TestBrowserThreadBundle thread_bundle_; | 1741 content::TestBrowserThreadBundle thread_bundle_; |
1726 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; | 1742 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; |
1727 | 1743 |
1728 #if defined OS_CHROMEOS | 1744 #if defined OS_CHROMEOS |
1729 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 1745 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
1730 chromeos::ScopedTestCrosSettings test_cros_settings_; | 1746 chromeos::ScopedTestCrosSettings test_cros_settings_; |
1731 chromeos::ScopedTestUserManager test_user_manager_; | 1747 chromeos::ScopedTestUserManager test_user_manager_; |
1732 #endif | 1748 #endif |
1733 }; | 1749 }; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1996 ASSERT_TRUE(fetcher); | 2012 ASSERT_TRUE(fetcher); |
1997 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); | 2013 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); |
1998 } | 2014 } |
1999 | 2015 |
2000 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { | 2016 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { |
2001 net::TestURLFetcherFactory factory; | 2017 net::TestURLFetcherFactory factory; |
2002 MockService service(prefs_.get()); | 2018 MockService service(prefs_.get()); |
2003 MockExtensionDownloaderDelegate delegate; | 2019 MockExtensionDownloaderDelegate delegate; |
2004 ExtensionDownloader downloader(&delegate, service.request_context()); | 2020 ExtensionDownloader downloader(&delegate, service.request_context()); |
2005 | 2021 |
2006 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0)); | 2022 StartUpdateCheck(&downloader, CreateManifestFetchData(GURL())); |
2007 // This should delete the newly-created ManifestFetchData. | 2023 // This should delete the newly-created ManifestFetchData. |
2008 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0)); | 2024 StartUpdateCheck(&downloader, CreateManifestFetchData(GURL())); |
2009 // This should add into |manifests_pending_|. | 2025 // This should add into |manifests_pending_|. |
2010 StartUpdateCheck(&downloader, new ManifestFetchData(GURL( | 2026 StartUpdateCheck(&downloader, |
2011 GURL("http://www.google.com")), 0)); | 2027 CreateManifestFetchData(GURL("http://www.google.com"))); |
2012 // The dtor of |downloader| should delete the pending fetchers. | 2028 // The dtor of |downloader| should delete the pending fetchers. |
2013 } | 2029 } |
2014 | 2030 |
2015 TEST_F(ExtensionUpdaterTest, TestCheckSoon) { | 2031 TEST_F(ExtensionUpdaterTest, TestCheckSoon) { |
2016 ServiceForManifestTests service(prefs_.get()); | 2032 ServiceForManifestTests service(prefs_.get()); |
2017 net::TestURLFetcherFactory factory; | 2033 net::TestURLFetcherFactory factory; |
2018 ExtensionUpdater updater(&service, | 2034 ExtensionUpdater updater(&service, |
2019 service.extension_prefs(), | 2035 service.extension_prefs(), |
2020 service.pref_service(), | 2036 service.pref_service(), |
2021 service.profile(), | 2037 service.profile(), |
(...skipping 19 matching lines...) Expand all Loading... |
2041 // -prodversionmin (shouldn't update if browser version too old) | 2057 // -prodversionmin (shouldn't update if browser version too old) |
2042 // -manifests & updates arriving out of order / interleaved | 2058 // -manifests & updates arriving out of order / interleaved |
2043 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 2059 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
2044 // -An extension gets uninstalled while updates are in progress (so it doesn't | 2060 // -An extension gets uninstalled while updates are in progress (so it doesn't |
2045 // "come back from the dead") | 2061 // "come back from the dead") |
2046 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 2062 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
2047 // you don't get downgraded accidentally) | 2063 // you don't get downgraded accidentally) |
2048 // -An update manifest mentions multiple updates | 2064 // -An update manifest mentions multiple updates |
2049 | 2065 |
2050 } // namespace extensions | 2066 } // namespace extensions |
OLD | NEW |