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

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

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

Powered by Google App Engine
This is Rietveld 408576698