diff options
-rw-r--r-- | chrome/app/generated_resources.grd | 4 | ||||
-rw-r--r-- | chrome/browser/download/download_item_model.cc | 70 | ||||
-rw-r--r-- | chrome/browser/download/download_item_model.h | 7 | ||||
-rw-r--r-- | chrome/browser/download/download_item_model_unittest.cc | 118 | ||||
-rw-r--r-- | chrome/browser/download/download_util.cc | 3 | ||||
-rw-r--r-- | chrome/browser/resources/downloads/downloads.css | 4 | ||||
-rw-r--r-- | chrome/browser/resources/downloads/downloads.js | 5 | ||||
-rw-r--r-- | chrome/browser/ui/webui/downloads_ui.cc | 2 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 |
9 files changed, 204 insertions, 10 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 3bf5c32..5e976ff 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -2317,10 +2317,6 @@ are declared in build/common.gypi. desc="Link label shown at the corner of the download shelf"> Show all downloads... </message> - <message name="IDS_DOWNLOAD_STATUS_INTERRUPTED" - desc="The download experienced an error and was interrupted, size downloaded/total."> - <ph name="DOWNLOAD_RECEIVED">$1<ex>54kB</ex></ph>/<ph name="DOWNLOAD_TOTAL">$2<ex>154MB</ex></ph>, Interrupted - </message> <!-- Download Error Messages--> <!-- *_STATUS_*: Short message in the download on the shelf.--> <!-- *_DESCRIPTION_*: Corresponding more descriptive message on the download page.--> diff --git a/chrome/browser/download/download_item_model.cc b/chrome/browser/download/download_item_model.cc index 187d6a3..87785ea 100644 --- a/chrome/browser/download/download_item_model.cc +++ b/chrome/browser/download/download_item_model.cc @@ -12,6 +12,7 @@ #include "chrome/browser/download/chrome_download_manager_delegate.h" #include "chrome/common/time_format.h" #include "content/public/browser/download_danger_type.h" +#include "content/public/browser/download_interrupt_reasons.h" #include "content/public/browser/download_item.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -70,7 +71,9 @@ string16 DownloadItemModel::GetStatusText() { TimeFormat::TimeRemaining(remaining); } + string16 size_text; string16 status_text; + content::DownloadInterruptReason reason; switch (download_->GetState()) { case DownloadItem::IN_PROGRESS: #if defined(OS_CHROMEOS) @@ -127,9 +130,18 @@ string16 DownloadItemModel::GetStatusText() { case DownloadItem::REMOVING: break; case DownloadItem::INTERRUPTED: - status_text = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_INTERRUPTED, + reason = download_->GetLastReason(); + status_text = InterruptReasonStatusMessage(reason); + if (total <= 0) { + size_text = ui::FormatBytes(size); + } else { + size_text = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_RECEIVED_SIZE, simple_size, simple_total); + } + size_text = size_text + ASCIIToUTF16(" "); + if (reason != content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED) + status_text = size_text + status_text; break; default: NOTREACHED(); @@ -226,6 +238,62 @@ bool DownloadItemModel::IsDangerous() { } // static +string16 BaseDownloadItemModel::InterruptReasonStatusMessage(int reason) { + int string_id = 0; + + switch (reason) { + case content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED: + string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_ACCESS_DENIED; + break; + case content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE: + string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_DISK_FULL; + break; + case content::DOWNLOAD_INTERRUPT_REASON_FILE_NAME_TOO_LONG: + string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_PATH_TOO_LONG; + break; + case content::DOWNLOAD_INTERRUPT_REASON_FILE_TOO_LARGE: + string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_FILE_TOO_LARGE; + break; + case content::DOWNLOAD_INTERRUPT_REASON_FILE_VIRUS_INFECTED: + string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_VIRUS; + break; + case content::DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR: + string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_TEMPORARY_PROBLEM; + break; + case content::DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT: + string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_NETWORK_TIMEOUT; + break; + case content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED: + string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_NETWORK_DISCONNECTED; + break; + case content::DOWNLOAD_INTERRUPT_REASON_NETWORK_SERVER_DOWN: + string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_SERVER_DOWN; + break; + case content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED: + string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_NETWORK_ERROR; + break; + case content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT: + string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_NO_FILE; + break; + case content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED: + string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_SERVER_PROBLEM; + break; + case content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN: + case content::DOWNLOAD_INTERRUPT_REASON_CRASH: + string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_SHUTDOWN; + break; + case content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED: + string_id = IDS_DOWNLOAD_STATUS_CANCELED; + break; + default: + string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS; + break; + } + + return l10n_util::GetStringUTF16(string_id); +} + +// static string16 BaseDownloadItemModel::InterruptReasonMessage(int reason) { int string_id = 0; string16 status_text; diff --git a/chrome/browser/download/download_item_model.h b/chrome/browser/download/download_item_model.h index 970e664..bddf911 100644 --- a/chrome/browser/download/download_item_model.h +++ b/chrome/browser/download/download_item_model.h @@ -54,11 +54,14 @@ class BaseDownloadItemModel { // Is this considered a dangerous download? virtual bool IsDangerous() = 0; + content::DownloadItem* download() { return download_; } + + // Get the status message of the given interrupt |reason|. + static string16 InterruptReasonStatusMessage(int reason); + // Get the description of the given interrupt |reason|. static string16 InterruptReasonMessage(int reason); - content::DownloadItem* download() { return download_; } - protected: content::DownloadItem* download_; }; diff --git a/chrome/browser/download/download_item_model_unittest.cc b/chrome/browser/download/download_item_model_unittest.cc new file mode 100644 index 0000000..9f32de2 --- /dev/null +++ b/chrome/browser/download/download_item_model_unittest.cc @@ -0,0 +1,118 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/download/download_item_model.h" + +#include "base/i18n/rtl.h" +#include "base/logging.h" +#include "base/message_loop.h" +#include "base/string16.h" +#include "base/utf_string_conversions.h" +#include "content/test/mock_download_item.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "grit/generated_resources.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/base/text/bytes_formatting.h" + +using ::testing::AtLeast; +using ::testing::Mock; +using ::testing::NiceMock; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::ReturnRefOfCopy; +using ::testing::SetArgPointee; +using ::testing::StrictMock; +using ::testing::_; + +content::DownloadId::Domain kValidIdDomain = "valid DownloadId::Domain"; + +class DownloadItemModelTest : public testing::Test { + public: + DownloadItemModelTest() {} + + virtual ~DownloadItemModelTest() { + } + + protected: + void SetupDownloadItemDefaults() { + ON_CALL(item_, GetReceivedBytes()).WillByDefault(Return(1024)); + ON_CALL(item_, GetTotalBytes()).WillByDefault(Return(2048)); + ON_CALL(item_, IsInProgress()).WillByDefault(Return(false)); + ON_CALL(item_, TimeRemaining(_)).WillByDefault(Return(false)); + ON_CALL(item_, GetState()). + WillByDefault(Return(content::DownloadItem::INTERRUPTED)); + ON_CALL(item_, PromptUserForSaveLocation()). + WillByDefault(Return(false)); + ON_CALL(item_, GetMimeType()).WillByDefault(Return("text/html")); + ON_CALL(item_, AllDataSaved()).WillByDefault(Return(false)); + ON_CALL(item_, GetOpenWhenComplete()).WillByDefault(Return(false)); + ON_CALL(item_, GetFileExternallyRemoved()).WillByDefault(Return(false)); + } + + void SetupDownloadItem(const GURL& url, + content::DownloadInterruptReason reason) { + model_.reset(new DownloadItemModel(&item_)); + EXPECT_CALL(item_, GetURL()).WillRepeatedly(ReturnRefOfCopy(url)); + EXPECT_CALL(item_, GetLastReason()).WillOnce(Return(reason)); + } + + void TestDownloadItemModelStatusText( + const GURL& url, content::DownloadInterruptReason reason) { + SetupDownloadItem(url, reason); + + int64 size = item_.GetReceivedBytes(); + int64 total = item_.GetTotalBytes(); + bool know_size = (total > 0); + + ui::DataUnits amount_units = ui::GetByteDisplayUnits(total); + string16 simple_size = ui::FormatBytesWithUnits(size, amount_units, false); + string16 simple_total = base::i18n::GetDisplayStringInLTRDirectionality( + ui::FormatBytesWithUnits(total, amount_units, true)); + + string16 status_text; + string16 size_text; + + status_text = DownloadItemModel::InterruptReasonStatusMessage(reason); + + if (know_size) { + size_text = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_RECEIVED_SIZE, + simple_size, + simple_total); + } else { + size_text = ui::FormatBytes(size); + } + size_text = size_text + ASCIIToUTF16(" "); + if (reason != content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED) + status_text = size_text + status_text; + + DVLOG(2) << " " << __FUNCTION__ << "()" << " '" << status_text << "'"; + + string16 text = model_->GetStatusText(); + + EXPECT_EQ(status_text, text); + } + + void TestDownloadItemModelStatusTextAllReasons(const GURL& url) { + SetupDownloadItemDefaults(); + +#define INTERRUPT_REASON(name, value) \ + TestDownloadItemModelStatusText(url, \ + content::DOWNLOAD_INTERRUPT_REASON_##name); + + #include "content/public/browser/download_interrupt_reason_values.h" + +#undef INTERRUPT_REASON + } + + private: + scoped_ptr<DownloadItemModel> model_; + + NiceMock<content::MockDownloadItem> item_; +}; + +// Test download error messages. +TEST_F(DownloadItemModelTest, Interrupts) { + TestDownloadItemModelStatusTextAllReasons(GURL("http://foo.bar/")); +} diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index d1eb22a..5bfa4e2 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -496,6 +496,9 @@ DictionaryValue* CreateDownloadItemValue(DownloadItem* download, int id) { static_cast<int>(download->PercentComplete())); file_value->SetInteger("received", static_cast<int>(download->GetReceivedBytes())); + file_value->SetString("last_reason_text", + BaseDownloadItemModel::InterruptReasonMessage( + download->GetLastReason())); } else if (download->IsCancelled()) { file_value->SetString("state", "CANCELLED"); } else if (download->IsComplete()) { diff --git a/chrome/browser/resources/downloads/downloads.css b/chrome/browser/resources/downloads/downloads.css index e85b734..763132c 100644 --- a/chrome/browser/resources/downloads/downloads.css +++ b/chrome/browser/resources/downloads/downloads.css @@ -121,6 +121,10 @@ html[dir=rtl] .progress { word-break: break-all; } +.interrupted { + color: red; +} + .download .status { color: #999; white-space: nowrap; diff --git a/chrome/browser/resources/downloads/downloads.js b/chrome/browser/resources/downloads/downloads.js index bdc2cc7..82244d4 100644 --- a/chrome/browser/resources/downloads/downloads.js +++ b/chrome/browser/resources/downloads/downloads.js @@ -387,6 +387,7 @@ Download.prototype.update = function(download) { this.state_ = download.state; this.fileExternallyRemoved_ = download.file_externally_removed; this.dangerType_ = download.danger_type; + this.lastReasonDescription_ = download.last_reason_text; this.since_ = download.since_string; this.date_ = download.date_string; @@ -424,6 +425,8 @@ Download.prototype.update = function(download) { } else if (this.nodeFileName_.textContent != this.fileName_) { this.nodeFileName_.textContent = this.fileName_; } + if (this.state_ == Download.States.INTERRUPTED) + this.nodeFileName_.classList.add('interrupted'); showInline(this.nodeFileLink_, this.state_ == Download.States.COMPLETE && @@ -530,7 +533,7 @@ Download.prototype.getStatusText_ = function() { 'danger_file_desc' : 'danger_url_desc'; return localStrings.getString(desc); case Download.States.INTERRUPTED: - return localStrings.getString('status_interrupted'); + return this.lastReasonDescription_; case Download.States.COMPLETE: return this.fileExternallyRemoved_ ? localStrings.getString('status_removed') : ''; diff --git a/chrome/browser/ui/webui/downloads_ui.cc b/chrome/browser/ui/webui/downloads_ui.cc index 64cbe72..f058455 100644 --- a/chrome/browser/ui/webui/downloads_ui.cc +++ b/chrome/browser/ui/webui/downloads_ui.cc @@ -46,8 +46,6 @@ ChromeWebUIDataSource* CreateDownloadsUIHTMLSource() { source->AddLocalizedString("status_cancelled", IDS_DOWNLOAD_TAB_CANCELED); source->AddLocalizedString("status_removed", IDS_DOWNLOAD_FILE_REMOVED); source->AddLocalizedString("status_paused", IDS_DOWNLOAD_PROGRESS_PAUSED); - source->AddLocalizedString("status_interrupted", - IDS_DOWNLOAD_PROGRESS_INTERRUPTED); // Dangerous file. source->AddLocalizedString("danger_file_desc", IDS_PROMPT_DANGEROUS_DOWNLOAD); diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index f68157d..017e191 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1400,6 +1400,7 @@ 'browser/cookies_tree_model_unittest.cc', 'browser/custom_handlers/protocol_handler_registry_unittest.cc', 'browser/diagnostics/diagnostics_model_unittest.cc', + 'browser/download/download_item_model_unittest.cc', 'browser/download/download_request_infobar_delegate_unittest.cc', 'browser/download/download_request_limiter_unittest.cc', 'browser/download/download_shelf_unittest.cc', |