Chromium Code Reviews| Index: chrome/browser/download/download_test_observer.h |
| diff --git a/chrome/browser/download/download_test_observer.h b/chrome/browser/download/download_test_observer.h |
| index 837b985a4400ff8c4ad3edf6a03c4e421d74d4a0..b6506be8ee73d99e7c2a80d12298a35803169f84 100644 |
| --- a/chrome/browser/download/download_test_observer.h |
| +++ b/chrome/browser/download/download_test_observer.h |
| @@ -7,11 +7,13 @@ |
| #pragma once |
| #include <set> |
| +#include <vector> |
| #include "base/basictypes.h" |
| #include "base/memory/ref_counted.h" |
| #include "content/public/browser/download_item.h" |
| #include "content/public/browser/download_manager.h" |
| +#include "net/base/net_errors.h" |
| // Detects changes to the downloads after construction. |
| // Finishes when one of the following happens: |
| @@ -200,4 +202,54 @@ class DownloadTestFlushObserver |
| DISALLOW_COPY_AND_ASSIGN(DownloadTestFlushObserver); |
| }; |
| +// Waits for a callback indicating that the DownloadItem is about to be created, |
| +// or that an error occurred and it won't be created. |
| +class DownloadTestItemCreationObserver |
| + : public base::RefCountedThreadSafe<DownloadTestItemCreationObserver> { |
| + public: |
| + struct CreationInfo { |
|
Randy Smith (Not in Mondays)
2012/03/06 21:29:14
Sorry to be pedantic about test code, but good cla
ahendrickson
2012/03/07 02:58:12
Done.
|
| + CreationInfo() |
| + : download_id(content::DownloadId::Invalid()), |
| + error(net::OK) { |
| + } |
| + |
| + content::DownloadId download_id; |
| + net::Error error; |
| + }; |
| + |
| + DownloadTestItemCreationObserver(); |
| + |
| + void WaitForDownloadItemCreation(); |
| + |
| + content::DownloadId download_id() const { |
| + return creation_info_.download_id; |
| + } |
| + net::Error error() const { return creation_info_.error; } |
| + bool started() const { return called_back_count_ > 0; } |
| + bool succeeded() const { |
| + return started() && (creation_info_.error == net::OK); |
| + } |
| + |
| + const content::DownloadManager::OnStartedCallback callback(); |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<DownloadTestItemCreationObserver>; |
| + |
| + ~DownloadTestItemCreationObserver(); |
| + |
| + void DownloadItemCreationCallback(content::DownloadId download_id, |
| + net::Error error); |
| + |
| + // The download creation information we received. |
| + CreationInfo creation_info_; |
| + |
| + // Count of callbacks. |
| + size_t called_back_count_; |
| + |
| + // We are in the message loop. |
| + bool waiting_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DownloadTestItemCreationObserver); |
| +}; |
| + |
| #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ |