Chromium Code Reviews| Index: chrome/browser/extensions/updater/extension_updater_unittest.cc |
| diff --git a/chrome/browser/extensions/updater/extension_updater_unittest.cc b/chrome/browser/extensions/updater/extension_updater_unittest.cc |
| index 6296ddecdea3f8a0c80b5af53738ade9edc28f2b..a88530c737d3001d927cdc270edf1db2700c3311 100644 |
| --- a/chrome/browser/extensions/updater/extension_updater_unittest.cc |
| +++ b/chrome/browser/extensions/updater/extension_updater_unittest.cc |
| @@ -116,6 +116,8 @@ int kExpectedLoadFlags = |
| net::LOAD_DO_NOT_SAVE_COOKIES | |
| net::LOAD_DISABLE_CACHE; |
| +int kExpectedLoadFlagsForProtectedDownload = net::LOAD_DISABLE_CACHE; |
| + |
| const ManifestFetchData::PingData kNeverPingedData( |
| ManifestFetchData::kNeverPinged, ManifestFetchData::kNeverPinged, true); |
| @@ -1047,6 +1049,74 @@ class ExtensionUpdaterTest : public testing::Test { |
| EXPECT_EQ(extension_file_path, tmpfile_path); |
| } |
| + // Update a single extension in an environment where the download request |
| + // initially responds with a 403 status. Expect the fetcher to automatically |
| + // retry with cookies enabled. |
| + void TestSingleProtectedExtensionDownloading() { |
| + net::TestURLFetcherFactory factory; |
| + net::TestURLFetcher* fetcher = NULL; |
| + scoped_ptr<ServiceForDownloadTests> service( |
| + new ServiceForDownloadTests(prefs_.get())); |
| + ExtensionUpdater updater(service.get(), service->extension_prefs(), |
| + service->pref_service(), |
| + service->profile(), |
| + kUpdateFrequencySecs, |
| + NULL); |
| + updater.Start(); |
| + ResetDownloader( |
| + &updater, |
| + new ExtensionDownloader(&updater, service->request_context())); |
| + updater.downloader_->extensions_queue_.set_backoff_policy( |
| + &kNoBackoffPolicy); |
| + |
| + GURL test_url("http://localhost/extension.crx"); |
| + |
| + std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| + std::string hash; |
| + Version version("0.0.1"); |
| + std::set<int> requests; |
| + requests.insert(0); |
| + scoped_ptr<ExtensionDownloader::ExtensionFetch> fetch( |
| + new ExtensionDownloader::ExtensionFetch( |
| + id, test_url, hash, version.GetString(), requests)); |
| + updater.downloader_->FetchUpdatedExtension(fetch.Pass()); |
| + |
| + fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); |
| + EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| + EXPECT_TRUE(fetcher->GetLoadFlags() == kExpectedLoadFlags); |
| + |
| + // Fake a 403 response. |
| + fetcher->set_url(test_url); |
| + fetcher->set_status(net::URLRequestStatus()); |
| + fetcher->set_response_code(403); |
| + fetcher->delegate()->OnURLFetchComplete(fetcher); |
| + RunUntilIdle(); |
| + |
| + // Verify that the fetcher has been switched to protected download mode |
| + // so that cookies would be sent with the next request. |
| + fetcher = factory.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId); |
| + EXPECT_TRUE(fetcher != NULL && fetcher->delegate() != NULL); |
| + EXPECT_TRUE( |
| + fetcher->GetLoadFlags() == kExpectedLoadFlagsForProtectedDownload); |
| + |
| + // Attempt to fetch again after the auth failure, but succeed this time. |
| + base::FilePath extension_file_path(FILE_PATH_LITERAL("/whatever")); |
| + fetcher->set_url(test_url); |
| + fetcher->set_status(net::URLRequestStatus()); |
| + fetcher->set_response_code(200); |
| + fetcher->SetResponseFilePath(extension_file_path); |
| + fetcher->delegate()->OnURLFetchComplete(fetcher); |
| + |
| + RunUntilIdle(); |
| + |
| + // Verify installation would proceed as normal. |
| + EXPECT_EQ(id, service->extension_id()); |
| + base::FilePath tmpfile_path = service->install_path(); |
| + EXPECT_FALSE(tmpfile_path.empty()); |
| + EXPECT_EQ(test_url, service->download_url()); |
| + EXPECT_EQ(extension_file_path, tmpfile_path); |
| + } |
| + |
|
asargent_no_longer_on_chrome
2014/01/31 18:22:26
Can you also add a test that proves that going int
Ken Rockot(use gerrit already)
2014/01/31 22:12:58
Done. Also added a test to verify that non-https d
|
| // Two extensions are updated. If |updates_start_running| is true, the |
| // mock extensions service has UpdateExtension(...) return true, and |
| // the test is responsible for creating fake CrxInstallers. Otherwise, |
| @@ -1454,6 +1524,10 @@ TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingPendingWithRetry) { |
| TestSingleExtensionDownloading(true, true); |
| } |
| +TEST_F(ExtensionUpdaterTest, TestSingleProtectedExtensionDownloading) { |
| + TestSingleProtectedExtensionDownloading(); |
| +} |
| + |
| TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) { |
| TestMultipleExtensionDownloading(false); |
| } |