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

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

Issue 129873019: Support extension update dwnloads which require auth (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new tests, nits Created 6 years, 10 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
« no previous file with comments | « chrome/browser/extensions/updater/extension_downloader.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 false, 109 false,
110 }; 110 };
111 111
112 const char kEmptyUpdateUrlData[] = ""; 112 const char kEmptyUpdateUrlData[] = "";
113 113
114 int kExpectedLoadFlags = 114 int kExpectedLoadFlags =
115 net::LOAD_DO_NOT_SEND_COOKIES | 115 net::LOAD_DO_NOT_SEND_COOKIES |
116 net::LOAD_DO_NOT_SAVE_COOKIES | 116 net::LOAD_DO_NOT_SAVE_COOKIES |
117 net::LOAD_DISABLE_CACHE; 117 net::LOAD_DISABLE_CACHE;
118 118
119 int kExpectedLoadFlagsForProtectedDownload = net::LOAD_DISABLE_CACHE;
120
119 const ManifestFetchData::PingData kNeverPingedData( 121 const ManifestFetchData::PingData kNeverPingedData(
120 ManifestFetchData::kNeverPinged, ManifestFetchData::kNeverPinged, true); 122 ManifestFetchData::kNeverPinged, ManifestFetchData::kNeverPinged, true);
121 123
122 class MockExtensionDownloaderDelegate : public ExtensionDownloaderDelegate { 124 class MockExtensionDownloaderDelegate : public ExtensionDownloaderDelegate {
123 public: 125 public:
124 MOCK_METHOD4(OnExtensionDownloadFailed, void(const std::string&, 126 MOCK_METHOD4(OnExtensionDownloadFailed, void(const std::string&,
125 Error, 127 Error,
126 const PingResult&, 128 const PingResult&,
127 const std::set<int>&)); 129 const std::set<int>&));
128 MOCK_METHOD7(OnExtensionDownloadFinished, void(const std::string&, 130 MOCK_METHOD7(OnExtensionDownloadFinished, void(const std::string&,
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 1042
1041 // Expect that ExtensionUpdater asked the mock extensions service to install 1043 // Expect that ExtensionUpdater asked the mock extensions service to install
1042 // a file with the test data for the right id. 1044 // a file with the test data for the right id.
1043 EXPECT_EQ(id, service->extension_id()); 1045 EXPECT_EQ(id, service->extension_id());
1044 base::FilePath tmpfile_path = service->install_path(); 1046 base::FilePath tmpfile_path = service->install_path();
1045 EXPECT_FALSE(tmpfile_path.empty()); 1047 EXPECT_FALSE(tmpfile_path.empty());
1046 EXPECT_EQ(test_url, service->download_url()); 1048 EXPECT_EQ(test_url, service->download_url());
1047 EXPECT_EQ(extension_file_path, tmpfile_path); 1049 EXPECT_EQ(extension_file_path, tmpfile_path);
1048 } 1050 }
1049 1051
1052 // Update a single extension in an environment where the download request
1053 // initially responds with a 403 status. Expect the fetcher to automatically
1054 // retry with cookies enabled.
1055 void TestSingleProtectedExtensionDownloading(bool use_https, bool fail) {
1056 net::TestURLFetcherFactory factory;
1057 net::TestURLFetcher* fetcher = NULL;
1058 scoped_ptr<ServiceForDownloadTests> service(
1059 new ServiceForDownloadTests(prefs_.get()));
1060 ExtensionUpdater updater(service.get(), service->extension_prefs(),
1061 service->pref_service(),
1062 service->profile(),
1063 kUpdateFrequencySecs,
1064 NULL);
1065 updater.Start();
1066 ResetDownloader(
1067 &updater,
1068 new ExtensionDownloader(&updater, service->request_context()));
1069 updater.downloader_->extensions_queue_.set_backoff_policy(
1070 &kNoBackoffPolicy);
1071
1072 GURL test_url(use_https ? "https://localhost/extension.crx" :
1073 "http://localhost/extension.crx");
1074
1075 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1076 std::string hash;
1077 Version version("0.0.1");
1078 std::set<int> requests;
1079 requests.insert(0);
1080 scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch(
1081 new ExtensionDownloader::ExtensionFetch(
1082 id, test_url, hash, version.GetString(), requests));
1083 updater.downloader_->FetchUpdatedExtension(fetch.Pass());
1084
1085 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId);
1086 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
1087 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags);
1088
1089 // Fake a 403 response.
1090 fetcher->set_url(test_url);
1091 fetcher->set_status(net::URLRequestStatus());
1092 fetcher->set_response_code(403);
1093 fetcher->delegate()->OnURLFetchComplete(fetcher);
1094 RunUntilIdle();
1095
1096 // Verify that the fetcher has been switched to protected download mode
1097 // so that cookies would be sent with the next request (https only).
1098 fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId);
1099 EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL);
1100 if (use_https) {
1101 EXPECT_TRUE(
1102 fetcher->GetLoadFlags() == kExpectedLoadFlagsForProtectedDownload);
1103 } else {
1104 EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags);
1105 }
1106
1107 // Attempt to fetch again after the auth failure.
1108 if (fail) {
1109 // Fail and verify that the fetch queue is cleared.
1110 fetcher->set_url(test_url);
1111 fetcher->set_status(net::URLRequestStatus());
1112 fetcher->set_response_code(403);
1113 fetcher->delegate()->OnURLFetchComplete(fetcher);
1114 RunUntilIdle();
1115 EXPECT_EQ(0U, updater.downloader_->extensions_queue_.active_request());
1116 } else {
1117 // Succeed
1118 base::FilePath extension_file_path(FILE_PATH_LITERAL("/whatever"));
1119 fetcher->set_url(test_url);
1120 fetcher->set_status(net::URLRequestStatus());
1121 fetcher->set_response_code(200);
1122 fetcher->SetResponseFilePath(extension_file_path);
1123 fetcher->delegate()->OnURLFetchComplete(fetcher);
1124 RunUntilIdle();
1125
1126 // Verify installation would proceed as normal.
1127 EXPECT_EQ(id, service->extension_id());
1128 base::FilePath tmpfile_path = service->install_path();
1129 EXPECT_FALSE(tmpfile_path.empty());
1130 EXPECT_EQ(test_url, service->download_url());
1131 EXPECT_EQ(extension_file_path, tmpfile_path);
1132 }
1133 }
1134
1050 // Two extensions are updated. If |updates_start_running| is true, the 1135 // Two extensions are updated. If |updates_start_running| is true, the
1051 // mock extensions service has UpdateExtension(...) return true, and 1136 // mock extensions service has UpdateExtension(...) return true, and
1052 // the test is responsible for creating fake CrxInstallers. Otherwise, 1137 // the test is responsible for creating fake CrxInstallers. Otherwise,
1053 // UpdateExtension() returns false, signaling install failures. 1138 // UpdateExtension() returns false, signaling install failures.
1054 void TestMultipleExtensionDownloading(bool updates_start_running) { 1139 void TestMultipleExtensionDownloading(bool updates_start_running) {
1055 net::TestURLFetcherFactory factory; 1140 net::TestURLFetcherFactory factory;
1056 net::TestURLFetcher* fetcher = NULL; 1141 net::TestURLFetcher* fetcher = NULL;
1057 ServiceForDownloadTests service(prefs_.get()); 1142 ServiceForDownloadTests service(prefs_.get());
1058 ExtensionUpdater updater( 1143 ExtensionUpdater updater(
1059 &service, service.extension_prefs(), service.pref_service(), 1144 &service, service.extension_prefs(), service.pref_service(),
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 } 1532 }
1448 1533
1449 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingWithRetry) { 1534 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingWithRetry) {
1450 TestSingleExtensionDownloading(false, true); 1535 TestSingleExtensionDownloading(false, true);
1451 } 1536 }
1452 1537
1453 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingPendingWithRetry) { 1538 TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingPendingWithRetry) {
1454 TestSingleExtensionDownloading(true, true); 1539 TestSingleExtensionDownloading(true, true);
1455 } 1540 }
1456 1541
1542 TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloading) {
1543 TestSingleProtectedExtensionDownloading(true, false);
1544 }
1545
1546 TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloadingFailure) {
1547 TestSingleProtectedExtensionDownloading(true, true);
1548 }
1549
1550 TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloadingNoHTTPS) {
1551 TestSingleProtectedExtensionDownloading(false, false);
1552 }
1553
1457 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) { 1554 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) {
1458 TestMultipleExtensionDownloading(false); 1555 TestMultipleExtensionDownloading(false);
1459 } 1556 }
1460 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesSucceed) { 1557 TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesSucceed) {
1461 TestMultipleExtensionDownloading(true); 1558 TestMultipleExtensionDownloading(true);
1462 } 1559 }
1463 1560
1464 TEST_F(ExtensionUpdaterTest, TestManifestRetryDownloading) { 1561 TEST_F(ExtensionUpdaterTest, TestManifestRetryDownloading) {
1465 TestManifestRetryDownloading(); 1562 TestManifestRetryDownloading();
1466 } 1563 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1640 // -prodversionmin (shouldn't update if browser version too old) 1737 // -prodversionmin (shouldn't update if browser version too old)
1641 // -manifests & updates arriving out of order / interleaved 1738 // -manifests & updates arriving out of order / interleaved
1642 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 1739 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
1643 // -An extension gets uninstalled while updates are in progress (so it doesn't 1740 // -An extension gets uninstalled while updates are in progress (so it doesn't
1644 // "come back from the dead") 1741 // "come back from the dead")
1645 // -An extension gets manually updated to v3 while we're downloading v2 (ie 1742 // -An extension gets manually updated to v3 while we're downloading v2 (ie
1646 // you don't get downgraded accidentally) 1743 // you don't get downgraded accidentally)
1647 // -An update manifest mentions multiple updates 1744 // -An update manifest mentions multiple updates
1648 1745
1649 } // namespace extensions 1746 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/extension_downloader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698