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

Unified Diff: chrome/browser/download/download_test_observer.cc

Issue 9568003: Fixed issue with DownloadTestObserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed CLANG issue. Created 8 years, 9 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
Index: chrome/browser/download/download_test_observer.cc
diff --git a/chrome/browser/download/download_test_observer.cc b/chrome/browser/download/download_test_observer.cc
index 0cbcd0cea8b94433513d612add42506e05ecc87b..94f8f7d16d5e5de38218fda1706c56572bb4a8d5 100644
--- a/chrome/browser/download/download_test_observer.cc
+++ b/chrome/browser/download/download_test_observer.cc
@@ -19,9 +19,9 @@ using content::DownloadManager;
// These functions take scoped_refptr's to DownloadManager because they
// are posted to message queues, and hence may execute arbitrarily after
// their actual posting. Once posted, there is no connection between
-// these routines and the DownloadTestObserver class from which they came,
-// so the DownloadTestObserver's reference to the DownloadManager cannot
-// be counted on to keep the DownloadManager around.
+// these routines and the DownloadTestObserverTerminal class from which
+// they came, so the DownloadTestObserverTerminal's reference to the
+// DownloadManager cannot be counted on to keep the DownloadManager around.
// Fake user click on "Accept".
void AcceptDangerousDownload(scoped_refptr<DownloadManager> download_manager,
@@ -39,27 +39,23 @@ void DenyDangerousDownload(scoped_refptr<DownloadManager> download_manager,
download->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
}
-DownloadTestObserver::DownloadTestObserver(
+DownloadTestObserverTerminal::DownloadTestObserverTerminal(
DownloadManager* download_manager,
size_t wait_count,
- DownloadItem::DownloadState download_finished_state,
bool finish_on_select_file,
DangerousDownloadAction dangerous_download_action)
: download_manager_(download_manager),
wait_count_(wait_count),
finished_downloads_at_construction_(0),
waiting_(false),
- download_finished_state_(download_finished_state),
finish_on_select_file_(finish_on_select_file),
select_file_dialog_seen_(false),
dangerous_download_action_(dangerous_download_action) {
download_manager_->AddObserver(this); // Will call initial ModelChanged().
finished_downloads_at_construction_ = finished_downloads_.size();
- EXPECT_NE(DownloadItem::REMOVING, download_finished_state)
- << "Waiting for REMOVING is not supported. Try COMPLETE.";
}
-DownloadTestObserver::~DownloadTestObserver() {
+DownloadTestObserverTerminal::~DownloadTestObserverTerminal() {
for (DownloadSet::iterator it = downloads_observed_.begin();
it != downloads_observed_.end(); ++it)
(*it)->RemoveObserver(this);
@@ -67,7 +63,7 @@ DownloadTestObserver::~DownloadTestObserver() {
download_manager_->RemoveObserver(this);
}
-void DownloadTestObserver::WaitForFinished() {
+void DownloadTestObserverTerminal::WaitForFinished() {
if (!IsFinished()) {
waiting_ = true;
ui_test_utils::RunMessageLoop();
@@ -75,14 +71,14 @@ void DownloadTestObserver::WaitForFinished() {
}
}
-bool DownloadTestObserver::IsFinished() const {
+bool DownloadTestObserverTerminal::IsFinished() const {
if (finished_downloads_.size() - finished_downloads_at_construction_ >=
wait_count_)
return true;
return (finish_on_select_file_ && select_file_dialog_seen_);
}
-void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) {
+void DownloadTestObserverTerminal::OnDownloadUpdated(DownloadItem* download) {
// The REMOVING state indicates that the download is being destroyed.
// Stop observing. Do not do anything with it, as it is about to be gone.
if (download->GetState() == DownloadItem::REMOVING) {
@@ -129,12 +125,11 @@ void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) {
}
}
- if (download->GetState() == download_finished_state_) {
+ if (IsDownloadInFinalState(download))
DownloadInFinalState(download);
- }
}
-void DownloadTestObserver::ModelChanged(DownloadManager* manager) {
+void DownloadTestObserverTerminal::ModelChanged(DownloadManager* manager) {
DCHECK_EQ(manager, download_manager_);
// Regenerate DownloadItem observers. If there are any download items
@@ -171,20 +166,21 @@ void DownloadTestObserver::ModelChanged(DownloadManager* manager) {
}
}
-void DownloadTestObserver::SelectFileDialogDisplayed(
+void DownloadTestObserverTerminal::SelectFileDialogDisplayed(
DownloadManager* manager, int32 /* id */) {
DCHECK_EQ(manager, download_manager_);
select_file_dialog_seen_ = true;
SignalIfFinished();
}
-size_t DownloadTestObserver::NumDangerousDownloadsSeen() const {
+size_t DownloadTestObserverTerminal::NumDangerousDownloadsSeen() const {
return dangerous_downloads_seen_.size();
}
-void DownloadTestObserver::DownloadInFinalState(DownloadItem* download) {
+void DownloadTestObserverTerminal::DownloadInFinalState(
+ DownloadItem* download) {
if (finished_downloads_.find(download) != finished_downloads_.end()) {
- // We've already seen terminal state on this download.
+ // We've already seen the final state on this download.
return;
}
@@ -194,11 +190,34 @@ void DownloadTestObserver::DownloadInFinalState(DownloadItem* download) {
SignalIfFinished();
}
-void DownloadTestObserver::SignalIfFinished() {
+bool DownloadTestObserverTerminal::IsDownloadInFinalState(
+ content::DownloadItem* download) {
+ return (download->GetState() != DownloadItem::IN_PROGRESS);
+}
+
+void DownloadTestObserverTerminal::SignalIfFinished() {
if (waiting_ && IsFinished())
MessageLoopForUI::current()->Quit();
}
+DownloadTestObserverInProgress::DownloadTestObserverInProgress(
+ content::DownloadManager* download_manager,
+ size_t wait_count)
+ : DownloadTestObserverTerminal(download_manager,
+ wait_count,
+ true,
+ ON_DANGEROUS_DOWNLOAD_FAIL) {
+}
+
+DownloadTestObserverInProgress::~DownloadTestObserverInProgress() {
+}
+
+
+bool DownloadTestObserverInProgress::IsDownloadInFinalState(
+ content::DownloadItem* download) {
+ return (download->GetState() == DownloadItem::IN_PROGRESS);
+}
+
DownloadTestFlushObserver::DownloadTestFlushObserver(
DownloadManager* download_manager)
: download_manager_(download_manager),

Powered by Google App Engine
This is Rietveld 408576698