diff options
author | asanka@chromium.org <asanka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-21 05:16:20 +0000 |
---|---|---|
committer | asanka@chromium.org <asanka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-21 05:16:20 +0000 |
commit | 8dc0d4052bbc6e023577e372679d471da9717236 (patch) | |
tree | 66dfcb4cf588a040e3a93b1564ec30d9df618648 | |
parent | bdf5d6c29ae86f1814d9add5936d0a081b994f78 (diff) | |
download | chromium_src-8dc0d4052bbc6e023577e372679d471da9717236.zip chromium_src-8dc0d4052bbc6e023577e372679d471da9717236.tar.gz chromium_src-8dc0d4052bbc6e023577e372679d471da9717236.tar.bz2 |
[Downloads] Make DownloadTestObserverTerminal condition on IsDone
The terminal state of a download is determined by DownloadItem::IsDone()
rather than watching for a download that has a state other than
IN_PROGRESS.
BUG=7648
Review URL: https://chromiumcodereview.appspot.com/17450008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207711 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/browser/download/download_browsertest.cc | 19 | ||||
-rw-r--r-- | content/public/test/download_test_observer.cc | 25 | ||||
-rw-r--r-- | content/public/test/download_test_observer.h | 20 |
3 files changed, 58 insertions, 6 deletions
diff --git a/content/browser/download/download_browsertest.cc b/content/browser/download/download_browsertest.cc index fc08d58..fc44699 100644 --- a/content/browser/download/download_browsertest.cc +++ b/content/browser/download/download_browsertest.cc @@ -555,6 +555,13 @@ class DownloadContentTest : public ContentBrowserTest { return new DownloadCreateObserver(download_manager); } + DownloadTestObserver* CreateInterruptedWaiter( + Shell* shell, int num_downloads) { + DownloadManager* download_manager = DownloadManagerForShell(shell); + return new DownloadTestObserverInterrupted(download_manager, num_downloads, + DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); + } + // Note: Cannot be used with other alternative DownloadFileFactorys void SetupEnsureNoPendingDownloads() { DownloadManagerForShell(shell())->SetDownloadFileFactoryForTesting( @@ -636,7 +643,8 @@ class DownloadContentTest : public ContentBrowserTest { // that the interrupt is received properly (for download resumption // testing). void ReleaseRSTAndConfirmInterruptForResume(DownloadItem* download) { - scoped_ptr<DownloadTestObserver> rst_observer(CreateWaiter(shell(), 1)); + scoped_ptr<DownloadTestObserver> rst_observer( + CreateInterruptedWaiter(shell(), 1)); NavigateToURL(shell(), test_server()->GetURL("download-finish")); rst_observer->WaitForFinished(); EXPECT_EQ(DownloadItem::INTERRUPTED, download->GetState()); @@ -1249,7 +1257,8 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeWithFileInitError) { injector->InjectErrors(); // Start and watch for interrupt. - scoped_ptr<DownloadTestObserver> int_observer(CreateWaiter(shell(), 1)); + scoped_ptr<DownloadTestObserver> int_observer( + CreateInterruptedWaiter(shell(), 1)); DownloadItem* download(StartDownloadAndReturnItem(url)); int_observer->WaitForFinished(); ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); @@ -1299,7 +1308,8 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, injector->InjectErrors(); // Start and watch for interrupt. - scoped_ptr<DownloadTestObserver> int_observer(CreateWaiter(shell(), 1)); + scoped_ptr<DownloadTestObserver> int_observer( + CreateInterruptedWaiter(shell(), 1)); DownloadItem* download(StartDownloadAndReturnItem(url)); int_observer->WaitForFinished(); ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); @@ -1351,7 +1361,8 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeWithFileFinalRenameError) { injector->InjectErrors(); // Start and watch for interrupt. - scoped_ptr<DownloadTestObserver> int_observer(CreateWaiter(shell(), 1)); + scoped_ptr<DownloadTestObserver> int_observer( + CreateInterruptedWaiter(shell(), 1)); DownloadItem* download(StartDownloadAndReturnItem(url)); int_observer->WaitForFinished(); ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); diff --git a/content/public/test/download_test_observer.cc b/content/public/test/download_test_observer.cc index cc26ff0..2d322e5 100644 --- a/content/public/test/download_test_observer.cc +++ b/content/public/test/download_test_observer.cc @@ -255,7 +255,7 @@ DownloadTestObserverTerminal::~DownloadTestObserverTerminal() { bool DownloadTestObserverTerminal::IsDownloadInFinalState( DownloadItem* download) { - return (download->GetState() != DownloadItem::IN_PROGRESS); + return download->IsDone(); } DownloadTestObserverInProgress::DownloadTestObserverInProgress( @@ -281,6 +281,29 @@ bool DownloadTestObserverInProgress::IsDownloadInFinalState( !download->GetTargetFilePath().empty(); } +DownloadTestObserverInterrupted::DownloadTestObserverInterrupted( + DownloadManager* download_manager, + size_t wait_count, + DangerousDownloadAction dangerous_download_action) + : DownloadTestObserver(download_manager, + wait_count, + dangerous_download_action) { + // You can't rely on overriden virtual functions in a base class constructor; + // the virtual function table hasn't been set up yet. So, we have to do any + // work that depends on those functions in the derived class constructor + // instead. In this case, it's because of |IsDownloadInFinalState()|. + Init(); +} + +DownloadTestObserverInterrupted::~DownloadTestObserverInterrupted() { +} + + +bool DownloadTestObserverInterrupted::IsDownloadInFinalState( + DownloadItem* download) { + return download->GetState() == DownloadItem::INTERRUPTED; +} + DownloadTestFlushObserver::DownloadTestFlushObserver( DownloadManager* download_manager) : download_manager_(download_manager), diff --git a/content/public/test/download_test_observer.h b/content/public/test/download_test_observer.h index c5e9476..03dd588 100644 --- a/content/public/test/download_test_observer.h +++ b/content/public/test/download_test_observer.h @@ -170,7 +170,8 @@ class DownloadTestObserver : public DownloadManager::Observer, class DownloadTestObserverTerminal : public DownloadTestObserver { public: // Create an object that will be considered finished when |wait_count| - // download items have entered a terminal state (any but IN_PROGRESS). + // download items have entered a terminal state (DownloadItem::IsDone() is + // true). DownloadTestObserverTerminal( DownloadManager* download_manager, size_t wait_count, @@ -204,6 +205,23 @@ class DownloadTestObserverInProgress : public DownloadTestObserver { DISALLOW_COPY_AND_ASSIGN(DownloadTestObserverInProgress); }; +class DownloadTestObserverInterrupted : public DownloadTestObserver { + public: + // Create an object that will be considered finished when |wait_count| + // download items are interrupted. + DownloadTestObserverInterrupted( + DownloadManager* download_manager, + size_t wait_count, + DangerousDownloadAction dangerous_download_action); + + virtual ~DownloadTestObserverInterrupted(); + + private: + virtual bool IsDownloadInFinalState(DownloadItem* download) OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(DownloadTestObserverInterrupted); +}; + // The WaitForFlush() method on this class returns after: // * There are no IN_PROGRESS download items remaining on the // DownloadManager. |