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

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: Added check that download finished in expected state. Created 8 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 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..729d5bbc4e0846edf716a15b5c9af47247778ca3 100644
--- a/chrome/browser/download/download_test_observer.cc
+++ b/chrome/browser/download/download_test_observer.cc
@@ -55,6 +55,8 @@ DownloadTestObserver::DownloadTestObserver(
dangerous_download_action_(dangerous_download_action) {
download_manager_->AddObserver(this); // Will call initial ModelChanged().
finished_downloads_at_construction_ = finished_downloads_.size();
Randy Smith (Not in Mondays) 2012/03/01 21:07:53 This member variable is now redundant with keeping
ahendrickson 2012/03/02 17:29:41 The list excludes items that match download_finish
+ // Move the finished other downloads to an exclusion list.
+ finished_other_downloads_.swap(previously_finished_downloads_);
EXPECT_NE(DownloadItem::REMOVING, download_finished_state)
<< "Waiting for REMOVING is not supported. Try COMPLETE.";
}
@@ -73,11 +75,17 @@ void DownloadTestObserver::WaitForFinished() {
ui_test_utils::RunMessageLoop();
waiting_ = false;
}
+
+ // We do not expect to see downloads finishing in the wrong state.
+ EXPECT_EQ(0u, finished_other_downloads_.size());
Randy Smith (Not in Mondays) 2012/03/01 21:07:53 This is an extra constraint on behavior. We may n
ahendrickson 2012/03/02 17:29:41 Replaced with a logging statement.
}
bool DownloadTestObserver::IsFinished() const {
- if (finished_downloads_.size() - finished_downloads_at_construction_ >=
- wait_count_)
+ size_t finished_download_count =
+ finished_downloads_.size() +
+ finished_other_downloads_.size() -
+ finished_downloads_at_construction_;
+ if (finished_download_count >= wait_count_)
return true;
return (finish_on_select_file_ && select_file_dialog_seen_);
}
@@ -131,6 +139,8 @@ void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) {
if (download->GetState() == download_finished_state_) {
DownloadInFinalState(download);
+ } else if (download->GetState() != DownloadItem::IN_PROGRESS) {
+ DownloadInTerminalState(download);
}
}
@@ -182,9 +192,13 @@ size_t DownloadTestObserver::NumDangerousDownloadsSeen() const {
return dangerous_downloads_seen_.size();
}
+size_t DownloadTestObserver::NumOtherDownloadsSeen() const {
+ return finished_other_downloads_.size();
+}
+
void DownloadTestObserver::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,6 +208,34 @@ void DownloadTestObserver::DownloadInFinalState(DownloadItem* download) {
SignalIfFinished();
}
+void DownloadTestObserver::DownloadInTerminalState(DownloadItem* download) {
+ if (finished_downloads_.find(download) != finished_downloads_.end()) {
+ // We've already seen the final state on this download.
+ return;
+ }
+
+ if (previously_finished_downloads_.find(download) !=
+ previously_finished_downloads_.end()) {
+ // These occurred before we were constructed.
+ return;
+ }
+
+ if (finished_other_downloads_.find(download) !=
+ finished_other_downloads_.end()) {
+ // We've already seen the terminal state on this download.
+ return;
+ }
+
+ // Record the transition to a final state.
+ finished_other_downloads_.insert(download);
+
+ LOG(WARNING) << " " << __FUNCTION__ << "()"
+ << " download = " << download->DebugString(true);
+
+ SignalIfFinished();
+}
+
+
void DownloadTestObserver::SignalIfFinished() {
if (waiting_ && IsFinished())
MessageLoopForUI::current()->Quit();

Powered by Google App Engine
This is Rietveld 408576698