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

Unified Diff: chrome/browser/extensions/updater/extension_updater_unittest.cc

Issue 135473004: Add unittest that tests behavior when downloading a crx fails. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 5d873b19ccd0e34810dd2aec59d9984d937c6498..4607aaf060e1bf0e1f506722343d6ce16f6e1552 100644
--- a/chrome/browser/extensions/updater/extension_updater_unittest.cc
+++ b/chrome/browser/extensions/updater/extension_updater_unittest.cc
@@ -70,6 +70,7 @@ using base::Time;
using base::TimeDelta;
using content::BrowserThread;
using testing::DoAll;
+using testing::Invoke;
using testing::InvokeWithoutArgs;
using testing::Mock;
using testing::Return;
@@ -151,6 +152,27 @@ class MockExtensionDownloaderDelegate : public ExtensionDownloaderDelegate {
quit_closure_.Run();
}
+ void DelegateTo(ExtensionDownloaderDelegate* delegate) {
+ ON_CALL(*this, OnExtensionDownloadFailed(_, _, _, _))
+ .WillByDefault(Invoke(delegate,
+ &ExtensionDownloaderDelegate::OnExtensionDownloadFailed));
+ ON_CALL(*this, OnExtensionDownloadFinished(_, _, _, _, _, _, _))
+ .WillByDefault(Invoke(delegate,
+ &ExtensionDownloaderDelegate::OnExtensionDownloadFinished));
+ ON_CALL(*this, GetPingDataForExtension(_, _))
+ .WillByDefault(Invoke(delegate,
+ &ExtensionDownloaderDelegate::GetPingDataForExtension));
+ ON_CALL(*this, GetUpdateUrlData(_))
+ .WillByDefault(Invoke(delegate,
+ &ExtensionDownloaderDelegate::GetUpdateUrlData));
+ ON_CALL(*this, IsExtensionPending(_))
+ .WillByDefault(Invoke(delegate,
+ &ExtensionDownloaderDelegate::IsExtensionPending));
+ ON_CALL(*this, GetExtensionExistingVersion(_, _))
+ .WillByDefault(Invoke(delegate,
+ &ExtensionDownloaderDelegate::GetExtensionExistingVersion));
asargent_no_longer_on_chrome 2014/02/01 00:55:05 ZOMG gtest
+ }
+
private:
base::Closure quit_closure_;
};
@@ -966,7 +988,7 @@ class ExtensionUpdaterTest : public testing::Test {
Mock::VerifyAndClearExpectations(&delegate);
}
- void TestSingleExtensionDownloading(bool pending, bool retry) {
+ void TestSingleExtensionDownloading(bool pending, bool retry, bool fail) {
net::TestURLFetcherFactory factory;
net::TestURLFetcher* fetcher = NULL;
scoped_ptr<ServiceForDownloadTests> service(
@@ -977,9 +999,11 @@ class ExtensionUpdaterTest : public testing::Test {
kUpdateFrequencySecs,
NULL);
updater.Start();
+ MockExtensionDownloaderDelegate delegate;
+ delegate.DelegateTo(&updater);
ResetDownloader(
&updater,
- new ExtensionDownloader(&updater, service->request_context()));
+ new ExtensionDownloader(&delegate, service->request_context()));
updater.downloader_->extensions_queue_.set_backoff_policy(
&kNoBackoffPolicy);
@@ -1032,19 +1056,31 @@ class ExtensionUpdaterTest : public testing::Test {
fetcher->set_url(test_url);
fetcher->set_status(net::URLRequestStatus());
- fetcher->set_response_code(200);
- fetcher->SetResponseFilePath(extension_file_path);
+ if (fail) {
+ fetcher->set_response_code(404);
+ EXPECT_CALL(delegate, OnExtensionDownloadFailed(id, _, _, requests));
+ } else {
+ fetcher->set_response_code(200);
+ fetcher->SetResponseFilePath(extension_file_path);
+ EXPECT_CALL(delegate, OnExtensionDownloadFinished(
+ id, _, _, _, version.GetString(), _, requests));
+ }
fetcher->delegate()->OnURLFetchComplete(fetcher);
RunUntilIdle();
- // Expect that ExtensionUpdater asked the mock extensions service to install
- // a file with the test data for the right id.
- 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);
+ if (fail) {
+ // Don't expect any extension to have been installed.
+ EXPECT_TRUE(service->extension_id().empty());
+ } else {
+ // Expect that ExtensionUpdater asked the mock extensions service to
+ // install a file with the test data for the right id.
+ 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);
+ }
}
// Two extensions are updated. If |updates_start_running| is true, the
@@ -1439,19 +1475,31 @@ TEST_F(ExtensionUpdaterTest, TestMultipleManifestDownloading) {
}
TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloading) {
- TestSingleExtensionDownloading(false, false);
+ TestSingleExtensionDownloading(false, false, false);
}
TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingPending) {
- TestSingleExtensionDownloading(true, false);
+ TestSingleExtensionDownloading(true, false, false);
}
TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingWithRetry) {
- TestSingleExtensionDownloading(false, true);
+ TestSingleExtensionDownloading(false, true, false);
}
TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingPendingWithRetry) {
- TestSingleExtensionDownloading(true, true);
+ TestSingleExtensionDownloading(true, true, false);
+}
+
+TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailure) {
+ TestSingleExtensionDownloading(false, false, true);
+}
+
+TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailureWithRetry) {
+ TestSingleExtensionDownloading(false, true, true);
+}
+
+TEST_F(ExtensionUpdaterTest, TestSingleExtensionDownloadingFailurePending) {
+ TestSingleExtensionDownloading(true, false, true);
}
TEST_F(ExtensionUpdaterTest, TestMultipleExtensionDownloadingUpdatesFail) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698