Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: chrome/browser/extensions/updater/extension_updater_unittest.cc

Issue 465543004: Factor Chrome details out of update manifest fetching. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 15 matching lines...) Expand all
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/extension_downloader.h" 33 #include "chrome/browser/extensions/updater/extension_downloader.h"
34 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h" 34 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h"
35 #include "chrome/browser/extensions/updater/extension_updater.h" 35 #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" 36 #include "chrome/browser/extensions/updater/request_queue_impl.h"
38 #include "chrome/browser/google/google_brand.h" 37 #include "chrome/browser/google/google_brand.h"
39 #include "chrome/browser/prefs/pref_service_syncable.h" 38 #include "chrome/browser/prefs/pref_service_syncable.h"
40 #include "chrome/common/pref_names.h" 39 #include "chrome/common/pref_names.h"
41 #include "chrome/test/base/testing_profile.h" 40 #include "chrome/test/base/testing_profile.h"
42 #include "components/omaha_query_params/omaha_query_params.h" 41 #include "components/omaha_query_params/omaha_query_params.h"
43 #include "content/public/browser/notification_details.h" 42 #include "content/public/browser/notification_details.h"
44 #include "content/public/browser/notification_observer.h" 43 #include "content/public/browser/notification_observer.h"
45 #include "content/public/browser/notification_registrar.h" 44 #include "content/public/browser/notification_registrar.h"
46 #include "content/public/browser/notification_service.h" 45 #include "content/public/browser/notification_service.h"
47 #include "content/public/browser/notification_source.h" 46 #include "content/public/browser/notification_source.h"
48 #include "content/public/test/test_browser_thread_bundle.h" 47 #include "content/public/test/test_browser_thread_bundle.h"
49 #include "content/public/test/test_utils.h" 48 #include "content/public/test/test_utils.h"
50 #include "extensions/browser/extension_prefs.h" 49 #include "extensions/browser/extension_prefs.h"
51 #include "extensions/browser/extension_registry.h" 50 #include "extensions/browser/extension_registry.h"
52 #include "extensions/browser/extension_system.h" 51 #include "extensions/browser/extension_system.h"
52 #include "extensions/browser/updater/manifest_fetch_data.h"
53 #include "extensions/common/extension.h" 53 #include "extensions/common/extension.h"
54 #include "extensions/common/id_util.h" 54 #include "extensions/common/id_util.h"
55 #include "extensions/common/manifest_constants.h" 55 #include "extensions/common/manifest_constants.h"
56 #include "google_apis/gaia/fake_identity_provider.h" 56 #include "google_apis/gaia/fake_identity_provider.h"
57 #include "google_apis/gaia/fake_oauth2_token_service.h" 57 #include "google_apis/gaia/fake_oauth2_token_service.h"
58 #include "libxml/globals.h" 58 #include "libxml/globals.h"
59 #include "net/base/backoff_entry.h" 59 #include "net/base/backoff_entry.h"
60 #include "net/base/escape.h" 60 #include "net/base/escape.h"
61 #include "net/base/load_flags.h" 61 #include "net/base/load_flags.h"
62 #include "net/http/http_request_headers.h" 62 #include "net/http/http_request_headers.h"
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 349 }
350 350
351 protected: 351 protected:
352 TestExtensionPrefs* const prefs_; 352 TestExtensionPrefs* const prefs_;
353 TestingProfile profile_; 353 TestingProfile profile_;
354 PendingExtensionManager pending_extension_manager_; 354 PendingExtensionManager pending_extension_manager_;
355 355
356 private: 356 private:
357 scoped_ptr<ExtensionDownloader> CreateExtensionDownloader( 357 scoped_ptr<ExtensionDownloader> CreateExtensionDownloader(
358 ExtensionDownloaderDelegate* delegate) { 358 ExtensionDownloaderDelegate* delegate) {
359 return make_scoped_ptr(new ExtensionDownloader( 359 scoped_ptr<ExtensionDownloader> downloader(new ExtensionDownloader(
360 downloader_delegate_override_ ? downloader_delegate_override_ 360 downloader_delegate_override_ ? downloader_delegate_override_
361 : delegate, 361 : delegate,
362 request_context())); 362 request_context()));
363 downloader->EnablePingDataForDomain("google.com");
364 downloader->SetManifestQueryParams(
365 omaha_query_params::OmahaQueryParams::Get(
366 omaha_query_params::OmahaQueryParams::CRX));
367 return downloader.Pass();
363 } 368 }
364 369
365 scoped_ptr<ExtensionDownloader> CreateExtensionDownloaderWithIdentity( 370 scoped_ptr<ExtensionDownloader> CreateExtensionDownloaderWithIdentity(
366 ExtensionDownloaderDelegate* delegate) { 371 ExtensionDownloaderDelegate* delegate) {
367 scoped_ptr<FakeIdentityProvider> fake_identity_provider; 372 scoped_ptr<FakeIdentityProvider> fake_identity_provider;
368 fake_token_service_.reset(new FakeOAuth2TokenService()); 373 fake_token_service_.reset(new FakeOAuth2TokenService());
369 fake_identity_provider.reset(new FakeIdentityProvider( 374 fake_identity_provider.reset(new FakeIdentityProvider(
370 fake_token_service_.get())); 375 fake_token_service_.get()));
371 fake_identity_provider->LogIn(kFakeAccountId); 376 fake_identity_provider->LogIn(kFakeAccountId);
372 fake_token_service_->AddAccount(kFakeAccountId); 377 fake_token_service_->AddAccount(kFakeAccountId);
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 } 698 }
694 EXPECT_EQ("", params["uc"]); 699 EXPECT_EQ("", params["uc"]);
695 } 700 }
696 701
697 void TestUpdateUrlDataEmpty() { 702 void TestUpdateUrlDataEmpty() {
698 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 703 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
699 const std::string version = "1.0"; 704 const std::string version = "1.0";
700 705
701 // Make sure that an empty update URL data string does not cause a ap= 706 // Make sure that an empty update URL data string does not cause a ap=
702 // option to appear in the x= parameter. 707 // option to appear in the x= parameter.
703 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 708 scoped_ptr<ManifestFetchData> fetch_data(
704 fetch_data.AddExtension( 709 CreateManifestFetchData(GURL("http://localhost/foo")));
710 fetch_data->AddExtension(
705 id, version, &kNeverPingedData, std::string(), std::string()); 711 id, version, &kNeverPingedData, std::string(), std::string());
706 712
707 std::map<std::string, std::string> params; 713 std::map<std::string, std::string> params;
708 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params); 714 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params);
709 EXPECT_EQ(id, params["id"]); 715 EXPECT_EQ(id, params["id"]);
710 EXPECT_EQ(version, params["v"]); 716 EXPECT_EQ(version, params["v"]);
711 EXPECT_EQ(0U, params.count("ap")); 717 EXPECT_EQ(0U, params.count("ap"));
712 } 718 }
713 719
714 void TestUpdateUrlDataSimple() { 720 void TestUpdateUrlDataSimple() {
715 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 721 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
716 const std::string version = "1.0"; 722 const std::string version = "1.0";
717 723
718 // Make sure that an update URL data string causes an appropriate ap= 724 // Make sure that an update URL data string causes an appropriate ap=
719 // option to appear in the x= parameter. 725 // option to appear in the x= parameter.
720 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 726 scoped_ptr<ManifestFetchData> fetch_data(
721 fetch_data.AddExtension( 727 CreateManifestFetchData(GURL("http://localhost/foo")));
728 fetch_data->AddExtension(
722 id, version, &kNeverPingedData, "bar", std::string()); 729 id, version, &kNeverPingedData, "bar", std::string());
723 std::map<std::string, std::string> params; 730 std::map<std::string, std::string> params;
724 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params); 731 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params);
725 EXPECT_EQ(id, params["id"]); 732 EXPECT_EQ(id, params["id"]);
726 EXPECT_EQ(version, params["v"]); 733 EXPECT_EQ(version, params["v"]);
727 EXPECT_EQ("bar", params["ap"]); 734 EXPECT_EQ("bar", params["ap"]);
728 } 735 }
729 736
730 void TestUpdateUrlDataCompound() { 737 void TestUpdateUrlDataCompound() {
731 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 738 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
732 const std::string version = "1.0"; 739 const std::string version = "1.0";
733 740
734 // Make sure that an update URL data string causes an appropriate ap= 741 // Make sure that an update URL data string causes an appropriate ap=
735 // option to appear in the x= parameter. 742 // option to appear in the x= parameter.
736 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 743 scoped_ptr<ManifestFetchData> fetch_data(
737 fetch_data.AddExtension( 744 CreateManifestFetchData(GURL("http://localhost/foo")));
745 fetch_data->AddExtension(
738 id, version, &kNeverPingedData, "a=1&b=2&c", std::string()); 746 id, version, &kNeverPingedData, "a=1&b=2&c", std::string());
739 std::map<std::string, std::string> params; 747 std::map<std::string, std::string> params;
740 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params); 748 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params);
741 EXPECT_EQ(id, params["id"]); 749 EXPECT_EQ(id, params["id"]);
742 EXPECT_EQ(version, params["v"]); 750 EXPECT_EQ(version, params["v"]);
743 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); 751 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]);
744 } 752 }
745 753
746 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { 754 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) {
747 net::TestURLFetcherFactory factory; 755 net::TestURLFetcherFactory factory;
748 756
749 MockService service(prefs_.get()); 757 MockService service(prefs_.get());
750 MockExtensionDownloaderDelegate delegate; 758 MockExtensionDownloaderDelegate delegate;
(...skipping 19 matching lines...) Expand all
770 std::string::size_type ap = update_url.find("ap%3D", x); 778 std::string::size_type ap = update_url.find("ap%3D", x);
771 EXPECT_EQ(std::string::npos, ap); 779 EXPECT_EQ(std::string::npos, ap);
772 } 780 }
773 781
774 void TestInstallSource() { 782 void TestInstallSource() {
775 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 783 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
776 const std::string version = "1.0"; 784 const std::string version = "1.0";
777 const std::string install_source = "instally"; 785 const std::string install_source = "instally";
778 786
779 // Make sure that an installsource= appears in the x= parameter. 787 // Make sure that an installsource= appears in the x= parameter.
780 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 788 scoped_ptr<ManifestFetchData> fetch_data(
781 fetch_data.AddExtension(id, version, &kNeverPingedData, 789 CreateManifestFetchData(GURL("http://localhost/foo")));
782 kEmptyUpdateUrlData, install_source); 790 fetch_data->AddExtension(
791 id, version, &kNeverPingedData, kEmptyUpdateUrlData, install_source);
783 std::map<std::string, std::string> params; 792 std::map<std::string, std::string> params;
784 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params); 793 VerifyQueryAndExtractParameters(fetch_data->full_url().query(), &params);
785 EXPECT_EQ(id, params["id"]); 794 EXPECT_EQ(id, params["id"]);
786 EXPECT_EQ(version, params["v"]); 795 EXPECT_EQ(version, params["v"]);
787 EXPECT_EQ(install_source, params["installsource"]); 796 EXPECT_EQ(install_source, params["installsource"]);
788 } 797 }
789 798
790 void TestDetermineUpdates() { 799 void TestDetermineUpdates() {
791 TestingProfile profile; 800 TestingProfile profile;
792 MockExtensionDownloaderDelegate delegate; 801 MockExtensionDownloaderDelegate delegate;
793 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); 802 ExtensionDownloader downloader(&delegate, profile.GetRequestContext());
794 803
795 // Check passing an empty list of parse results to DetermineUpdates 804 // Check passing an empty list of parse results to DetermineUpdates
796 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 805 scoped_ptr<ManifestFetchData> fetch_data(
806 CreateManifestFetchData(GURL("http://localhost/foo")));
797 UpdateManifest::Results updates; 807 UpdateManifest::Results updates;
798 std::vector<int> updateable; 808 std::vector<int> updateable;
799 downloader.DetermineUpdates(fetch_data, updates, &updateable); 809 downloader.DetermineUpdates(*fetch_data, updates, &updateable);
800 EXPECT_TRUE(updateable.empty()); 810 EXPECT_TRUE(updateable.empty());
801 811
802 // Create two updates - expect that DetermineUpdates will return the first 812 // Create two updates - expect that DetermineUpdates will return the first
803 // one (v1.0 installed, v1.1 available) but not the second one (both 813 // one (v1.0 installed, v1.1 available) but not the second one (both
804 // installed and available at v2.0). 814 // installed and available at v2.0).
805 const std::string id1 = id_util::GenerateId("1"); 815 const std::string id1 = id_util::GenerateId("1");
806 const std::string id2 = id_util::GenerateId("2"); 816 const std::string id2 = id_util::GenerateId("2");
807 fetch_data.AddExtension( 817 fetch_data->AddExtension(
808 id1, "1.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string()); 818 id1, "1.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string());
809 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates); 819 AddParseResult(id1, "1.1", "http://localhost/e1_1.1.crx", &updates);
810 fetch_data.AddExtension( 820 fetch_data->AddExtension(
811 id2, "2.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string()); 821 id2, "2.0.0.0", &kNeverPingedData, kEmptyUpdateUrlData, std::string());
812 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);
813 823
814 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false)); 824 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(false));
815 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _)) 825 EXPECT_CALL(delegate, GetExtensionExistingVersion(id1, _))
816 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"), 826 .WillOnce(DoAll(SetArgPointee<1>("1.0.0.0"),
817 Return(true))); 827 Return(true)));
818 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _)) 828 EXPECT_CALL(delegate, GetExtensionExistingVersion(id2, _))
819 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"), 829 .WillOnce(DoAll(SetArgPointee<1>("2.0.0.0"),
820 Return(true))); 830 Return(true)));
821 831
822 downloader.DetermineUpdates(fetch_data, updates, &updateable); 832 downloader.DetermineUpdates(*fetch_data, updates, &updateable);
823 EXPECT_EQ(1u, updateable.size()); 833 EXPECT_EQ(1u, updateable.size());
824 EXPECT_EQ(0, updateable[0]); 834 EXPECT_EQ(0, updateable[0]);
825 } 835 }
826 836
827 void TestDetermineUpdatesPending() { 837 void TestDetermineUpdatesPending() {
828 // Create a set of test extensions 838 // Create a set of test extensions
829 ServiceForManifestTests service(prefs_.get()); 839 ServiceForManifestTests service(prefs_.get());
830 PendingExtensionManager* pending_extension_manager = 840 PendingExtensionManager* pending_extension_manager =
831 service.pending_extension_manager(); 841 service.pending_extension_manager();
832 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); 842 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager);
833 843
834 TestingProfile profile; 844 TestingProfile profile;
835 MockExtensionDownloaderDelegate delegate; 845 MockExtensionDownloaderDelegate delegate;
836 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); 846 ExtensionDownloader downloader(&delegate, profile.GetRequestContext());
837 847
838 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 848 scoped_ptr<ManifestFetchData> fetch_data(
849 CreateManifestFetchData(GURL("http://localhost/foo")));
839 UpdateManifest::Results updates; 850 UpdateManifest::Results updates;
840 851
841 std::list<std::string> ids_for_update_check; 852 std::list<std::string> ids_for_update_check;
842 pending_extension_manager->GetPendingIdsForUpdateCheck( 853 pending_extension_manager->GetPendingIdsForUpdateCheck(
843 &ids_for_update_check); 854 &ids_for_update_check);
844 855
845 std::list<std::string>::const_iterator it; 856 std::list<std::string>::const_iterator it;
846 for (it = ids_for_update_check.begin(); 857 for (it = ids_for_update_check.begin();
847 it != ids_for_update_check.end(); ++it) { 858 it != ids_for_update_check.end(); ++it) {
848 fetch_data.AddExtension(*it, 859 fetch_data->AddExtension(*it,
849 "1.0.0.0", 860 "1.0.0.0",
850 &kNeverPingedData, 861 &kNeverPingedData,
851 kEmptyUpdateUrlData, 862 kEmptyUpdateUrlData,
852 std::string()); 863 std::string());
853 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates); 864 AddParseResult(*it, "1.1", "http://localhost/e1_1.1.crx", &updates);
854 } 865 }
855 866
856 // The delegate will tell the downloader that all the extensions are 867 // The delegate will tell the downloader that all the extensions are
857 // pending. 868 // pending.
858 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true)); 869 EXPECT_CALL(delegate, IsExtensionPending(_)).WillRepeatedly(Return(true));
859 870
860 std::vector<int> updateable; 871 std::vector<int> updateable;
861 downloader.DetermineUpdates(fetch_data, updates, &updateable); 872 downloader.DetermineUpdates(*fetch_data, updates, &updateable);
862 // All the apps should be updateable. 873 // All the apps should be updateable.
863 EXPECT_EQ(3u, updateable.size()); 874 EXPECT_EQ(3u, updateable.size());
864 for (std::vector<int>::size_type i = 0; i < updateable.size(); ++i) { 875 for (std::vector<int>::size_type i = 0; i < updateable.size(); ++i) {
865 EXPECT_EQ(static_cast<int>(i), updateable[i]); 876 EXPECT_EQ(static_cast<int>(i), updateable[i]);
866 } 877 }
867 } 878 }
868 879
869 void TestMultipleManifestDownloading() { 880 void TestMultipleManifestDownloading() {
870 net::TestURLFetcherFactory factory; 881 net::TestURLFetcherFactory factory;
871 factory.set_remove_fetcher_on_delete(true); 882 factory.set_remove_fetcher_on_delete(true);
872 net::TestURLFetcher* fetcher = NULL; 883 net::TestURLFetcher* fetcher = NULL;
873 MockService service(prefs_.get()); 884 MockService service(prefs_.get());
874 MockExtensionDownloaderDelegate delegate; 885 MockExtensionDownloaderDelegate delegate;
875 ExtensionDownloader downloader(&delegate, service.request_context()); 886 ExtensionDownloader downloader(&delegate, service.request_context());
876 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); 887 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy);
877 888
878 GURL kUpdateUrl("http://localhost/manifest1"); 889 GURL kUpdateUrl("http://localhost/manifest1");
879 890
880 scoped_ptr<ManifestFetchData> fetch1(new ManifestFetchData(kUpdateUrl, 0)); 891 scoped_ptr<ManifestFetchData> fetch1(CreateManifestFetchData(kUpdateUrl));
881 scoped_ptr<ManifestFetchData> fetch2(new ManifestFetchData(kUpdateUrl, 0)); 892 scoped_ptr<ManifestFetchData> fetch2(CreateManifestFetchData(kUpdateUrl));
882 scoped_ptr<ManifestFetchData> fetch3(new ManifestFetchData(kUpdateUrl, 0)); 893 scoped_ptr<ManifestFetchData> fetch3(CreateManifestFetchData(kUpdateUrl));
883 scoped_ptr<ManifestFetchData> fetch4(new ManifestFetchData(kUpdateUrl, 0)); 894 scoped_ptr<ManifestFetchData> fetch4(CreateManifestFetchData(kUpdateUrl));
884 ManifestFetchData::PingData zeroDays(0, 0, true); 895 ManifestFetchData::PingData zeroDays(0, 0, true);
885 fetch1->AddExtension( 896 fetch1->AddExtension(
886 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); 897 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string());
887 fetch2->AddExtension( 898 fetch2->AddExtension(
888 "2222", "2.0", &zeroDays, kEmptyUpdateUrlData, std::string()); 899 "2222", "2.0", &zeroDays, kEmptyUpdateUrlData, std::string());
889 fetch3->AddExtension( 900 fetch3->AddExtension(
890 "3333", "3.0", &zeroDays, kEmptyUpdateUrlData, std::string()); 901 "3333", "3.0", &zeroDays, kEmptyUpdateUrlData, std::string());
891 fetch4->AddExtension( 902 fetch4->AddExtension(
892 "4444", "4.0", &zeroDays, kEmptyUpdateUrlData, std::string()); 903 "4444", "4.0", &zeroDays, kEmptyUpdateUrlData, std::string());
893 904
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 net::TestURLFetcherFactory factory; 1021 net::TestURLFetcherFactory factory;
1011 net::TestURLFetcher* fetcher = NULL; 1022 net::TestURLFetcher* fetcher = NULL;
1012 NotificationsObserver observer; 1023 NotificationsObserver observer;
1013 MockService service(prefs_.get()); 1024 MockService service(prefs_.get());
1014 MockExtensionDownloaderDelegate delegate; 1025 MockExtensionDownloaderDelegate delegate;
1015 ExtensionDownloader downloader(&delegate, service.request_context()); 1026 ExtensionDownloader downloader(&delegate, service.request_context());
1016 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy); 1027 downloader.manifests_queue_.set_backoff_policy(&kNoBackoffPolicy);
1017 1028
1018 GURL kUpdateUrl("http://localhost/manifest1"); 1029 GURL kUpdateUrl("http://localhost/manifest1");
1019 1030
1020 scoped_ptr<ManifestFetchData> fetch(new ManifestFetchData(kUpdateUrl, 0)); 1031 scoped_ptr<ManifestFetchData> fetch(CreateManifestFetchData(kUpdateUrl));
1021 ManifestFetchData::PingData zeroDays(0, 0, true); 1032 ManifestFetchData::PingData zeroDays(0, 0, true);
1022 fetch->AddExtension( 1033 fetch->AddExtension(
1023 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); 1034 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string());
1024 1035
1025 // This will start the first fetcher. 1036 // This will start the first fetcher.
1026 downloader.StartUpdateCheck(fetch.Pass()); 1037 downloader.StartUpdateCheck(fetch.Pass());
1027 RunUntilIdle(); 1038 RunUntilIdle();
1028 1039
1029 // ExtensionDownloader should retry kMaxRetries times and then fail. 1040 // ExtensionDownloader should retry kMaxRetries times and then fail.
1030 EXPECT_CALL(delegate, OnExtensionDownloadFailed( 1041 EXPECT_CALL(delegate, OnExtensionDownloadFailed(
1031 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); 1042 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _));
1032 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) { 1043 for (int i = 0; i <= ExtensionDownloader::kMaxRetries; ++i) {
1033 // All fetches will fail. 1044 // All fetches will fail.
1034 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 1045 fetcher = factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
1035 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); 1046 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
1036 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); 1047 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags);
1037 fetcher->set_url(kUpdateUrl); 1048 fetcher->set_url(kUpdateUrl);
1038 fetcher->set_status(net::URLRequestStatus()); 1049 fetcher->set_status(net::URLRequestStatus());
1039 // Code 5xx causes ExtensionDownloader to retry. 1050 // Code 5xx causes ExtensionDownloader to retry.
1040 fetcher->set_response_code(500); 1051 fetcher->set_response_code(500);
1041 fetcher->delegate()->OnURLFetchComplete(fetcher); 1052 fetcher->delegate()->OnURLFetchComplete(fetcher);
1042 RunUntilIdle(); 1053 RunUntilIdle();
1043 } 1054 }
1044 Mock::VerifyAndClearExpectations(&delegate); 1055 Mock::VerifyAndClearExpectations(&delegate);
1045 1056
1046 1057
1047 // For response codes that are not in the 5xx range ExtensionDownloader 1058 // For response codes that are not in the 5xx range ExtensionDownloader
1048 // should not retry. 1059 // should not retry.
1049 fetch.reset(new ManifestFetchData(kUpdateUrl, 0)); 1060 fetch.reset(CreateManifestFetchData(kUpdateUrl));
1050 fetch->AddExtension( 1061 fetch->AddExtension(
1051 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string()); 1062 "1111", "1.0", &zeroDays, kEmptyUpdateUrlData, std::string());
1052 1063
1053 // This will start the first fetcher. 1064 // This will start the first fetcher.
1054 downloader.StartUpdateCheck(fetch.Pass()); 1065 downloader.StartUpdateCheck(fetch.Pass());
1055 RunUntilIdle(); 1066 RunUntilIdle();
1056 1067
1057 EXPECT_CALL(delegate, OnExtensionDownloadFailed( 1068 EXPECT_CALL(delegate, OnExtensionDownloadFailed(
1058 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _)); 1069 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED, _, _));
1059 // The first fetch will fail, and require retrying. 1070 // The first fetch will fail, and require retrying.
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 ExtensionUpdater updater(&service, 1704 ExtensionUpdater updater(&service,
1694 service.extension_prefs(), 1705 service.extension_prefs(),
1695 service.pref_service(), 1706 service.pref_service(),
1696 service.profile(), 1707 service.profile(),
1697 kUpdateFrequencySecs, 1708 kUpdateFrequencySecs,
1698 NULL, 1709 NULL,
1699 service.GetDownloaderFactory()); 1710 service.GetDownloaderFactory());
1700 updater.Start(); 1711 updater.Start();
1701 updater.EnsureDownloaderCreated(); 1712 updater.EnsureDownloaderCreated();
1702 1713
1703 ManifestFetchData fetch_data(update_url, 0); 1714 scoped_ptr<ManifestFetchData> fetch_data(
1715 CreateManifestFetchData(update_url));
1704 const Extension* extension = tmp[0].get(); 1716 const Extension* extension = tmp[0].get();
1705 fetch_data.AddExtension(extension->id(), 1717 fetch_data->AddExtension(extension->id(),
1706 extension->VersionString(), 1718 extension->VersionString(),
1707 &kNeverPingedData, 1719 &kNeverPingedData,
1708 kEmptyUpdateUrlData, 1720 kEmptyUpdateUrlData,
1709 std::string()); 1721 std::string());
1710 UpdateManifest::Results results; 1722 UpdateManifest::Results results;
1711 results.daystart_elapsed_seconds = 750; 1723 results.daystart_elapsed_seconds = 750;
1712 1724
1713 updater.downloader_->HandleManifestResults(fetch_data, &results); 1725 updater.downloader_->HandleManifestResults(*fetch_data, &results);
1714 Time last_ping_day = 1726 Time last_ping_day =
1715 service.extension_prefs()->LastPingDay(extension->id()); 1727 service.extension_prefs()->LastPingDay(extension->id());
1716 EXPECT_FALSE(last_ping_day.is_null()); 1728 EXPECT_FALSE(last_ping_day.is_null());
1717 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds(); 1729 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds();
1718 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); 1730 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5);
1719 } 1731 }
1720 1732
1721 protected: 1733 protected:
1722 scoped_ptr<TestExtensionPrefs> prefs_; 1734 scoped_ptr<TestExtensionPrefs> prefs_;
1723 1735
1736 ManifestFetchData* CreateManifestFetchData(const GURL& update_url) {
1737 return new ManifestFetchData(
1738 update_url,
1739 0,
1740 "",
1741 omaha_query_params::OmahaQueryParams::Get(
not at google - send to devlin 2014/08/13 01:30:02 Ok, "omaha_query_params::OmahaQueryParams" looks v
1742 omaha_query_params::OmahaQueryParams::CRX),
1743 ManifestFetchData::PING);
1744 }
1745
1724 private: 1746 private:
1725 content::TestBrowserThreadBundle thread_bundle_; 1747 content::TestBrowserThreadBundle thread_bundle_;
1726 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; 1748 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_;
1727 1749
1728 #if defined OS_CHROMEOS 1750 #if defined OS_CHROMEOS
1729 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 1751 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
1730 chromeos::ScopedTestCrosSettings test_cros_settings_; 1752 chromeos::ScopedTestCrosSettings test_cros_settings_;
1731 chromeos::ScopedTestUserManager test_user_manager_; 1753 chromeos::ScopedTestUserManager test_user_manager_;
1732 #endif 1754 #endif
1733 }; 1755 };
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1996 ASSERT_TRUE(fetcher); 2018 ASSERT_TRUE(fetcher);
1997 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty()); 2019 EXPECT_FALSE(fetcher->GetOriginalURL().is_empty());
1998 } 2020 }
1999 2021
2000 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { 2022 TEST_F(ExtensionUpdaterTest, TestStartUpdateCheckMemory) {
2001 net::TestURLFetcherFactory factory; 2023 net::TestURLFetcherFactory factory;
2002 MockService service(prefs_.get()); 2024 MockService service(prefs_.get());
2003 MockExtensionDownloaderDelegate delegate; 2025 MockExtensionDownloaderDelegate delegate;
2004 ExtensionDownloader downloader(&delegate, service.request_context()); 2026 ExtensionDownloader downloader(&delegate, service.request_context());
2005 2027
2006 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0)); 2028 StartUpdateCheck(&downloader, CreateManifestFetchData(GURL()));
2007 // This should delete the newly-created ManifestFetchData. 2029 // This should delete the newly-created ManifestFetchData.
2008 StartUpdateCheck(&downloader, new ManifestFetchData(GURL(), 0)); 2030 StartUpdateCheck(&downloader, CreateManifestFetchData(GURL()));
2009 // This should add into |manifests_pending_|. 2031 // This should add into |manifests_pending_|.
2010 StartUpdateCheck(&downloader, new ManifestFetchData(GURL( 2032 StartUpdateCheck(&downloader,
2011 GURL("http://www.google.com")), 0)); 2033 CreateManifestFetchData(GURL("http://www.google.com")));
2012 // The dtor of |downloader| should delete the pending fetchers. 2034 // The dtor of |downloader| should delete the pending fetchers.
2013 } 2035 }
2014 2036
2015 TEST_F(ExtensionUpdaterTest, TestCheckSoon) { 2037 TEST_F(ExtensionUpdaterTest, TestCheckSoon) {
2016 ServiceForManifestTests service(prefs_.get()); 2038 ServiceForManifestTests service(prefs_.get());
2017 net::TestURLFetcherFactory factory; 2039 net::TestURLFetcherFactory factory;
2018 ExtensionUpdater updater(&service, 2040 ExtensionUpdater updater(&service,
2019 service.extension_prefs(), 2041 service.extension_prefs(),
2020 service.pref_service(), 2042 service.pref_service(),
2021 service.profile(), 2043 service.profile(),
(...skipping 19 matching lines...) Expand all
2041 // -prodversionmin (shouldn't update if browser version too old) 2063 // -prodversionmin (shouldn't update if browser version too old)
2042 // -manifests & updates arriving out of order / interleaved 2064 // -manifests & updates arriving out of order / interleaved
2043 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 2065 // -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 2066 // -An extension gets uninstalled while updates are in progress (so it doesn't
2045 // "come back from the dead") 2067 // "come back from the dead")
2046 // -An extension gets manually updated to v3 while we're downloading v2 (ie 2068 // -An extension gets manually updated to v3 while we're downloading v2 (ie
2047 // you don't get downgraded accidentally) 2069 // you don't get downgraded accidentally)
2048 // -An update manifest mentions multiple updates 2070 // -An update manifest mentions multiple updates
2049 2071
2050 } // namespace extensions 2072 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698