Index: chrome/browser/download/save_page_browsertest.cc |
=================================================================== |
--- chrome/browser/download/save_page_browsertest.cc (revision 153592) |
+++ chrome/browser/download/save_page_browsertest.cc (working copy) |
@@ -64,9 +64,6 @@ |
".html"; |
#endif |
-void NullFunction() { |
-} |
- |
} // namespace |
// Loosely based on logic in DownloadTestObserver. |
@@ -104,8 +101,7 @@ |
private: |
// DownloadManager::Observer |
- virtual void OnDownloadCreated( |
- DownloadManager* manager, DownloadItem* item) OVERRIDE { |
+ void OnDownloadCreated(DownloadManager* manager, DownloadItem* item) { |
DCHECK_EQ(manager, manager_); |
if (!created_item_) |
created_item_ = item; |
@@ -114,7 +110,7 @@ |
MessageLoopForUI::current()->Quit(); |
} |
- virtual void ManagerGoingDown(DownloadManager* manager) OVERRIDE { |
+ void ManagerGoingDownload(DownloadManager* manager) { |
manager_->RemoveObserver(this); |
manager_ = NULL; |
if (waiting_) |
@@ -128,60 +124,6 @@ |
DISALLOW_COPY_AND_ASSIGN(DownloadItemCreatedObserver); |
}; |
-class DownloadPersistedObserver : public DownloadItem::Observer { |
- public: |
- explicit DownloadPersistedObserver(DownloadItem* item) |
- : waiting_(false), item_(item) { |
- item->AddObserver(this); |
- } |
- |
- ~DownloadPersistedObserver() { |
- if (item_) |
- item_->RemoveObserver(this); |
- } |
- |
- // Wait for download item to get the persisted bit set. |
- // Note that this class provides no protection against the download |
- // being destroyed between creation and return of WaitForPersisted(); |
- // the caller must guarantee that in some other fashion. |
- void WaitForPersisted() { |
- // In combination with OnDownloadDestroyed() below, verify the |
- // above interface contract. |
- DCHECK(item_); |
- |
- if (item_->IsPersisted()) |
- return; |
- |
- waiting_ = true; |
- content::RunMessageLoop(); |
- waiting_ = false; |
- |
- return; |
- } |
- |
- private: |
- // DownloadItem::Observer |
- virtual void OnDownloadUpdated(DownloadItem* item) OVERRIDE { |
- DCHECK_EQ(item, item_); |
- |
- if (waiting_ && item->IsPersisted()) |
- MessageLoopForUI::current()->Quit(); |
- } |
- |
- virtual void OnDownloadDestroyed(DownloadItem* item) OVERRIDE { |
- if (item != item_) |
- return; |
- |
- item_->RemoveObserver(this); |
- item_ = NULL; |
- } |
- |
- bool waiting_; |
- DownloadItem* item_; |
- |
- DISALLOW_COPY_AND_ASSIGN(DownloadPersistedObserver); |
-}; |
- |
class SavePageBrowserTest : public InProcessBrowserTest { |
public: |
SavePageBrowserTest() {} |
@@ -223,12 +165,12 @@ |
return current_tab; |
} |
+ |
GURL WaitForSavePackageToFinish() const { |
content::WindowedNotificationObserver observer( |
content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
content::NotificationService::AllSources()); |
observer.Wait(); |
- |
return content::Details<DownloadItem>(observer.details()).ptr()-> |
GetOriginalUrl(); |
} |
@@ -267,12 +209,11 @@ |
DownloadPersistentStoreInfoMatch(const GURL& url, |
const FilePath& path, |
- int64 num_files, |
- DownloadItem::DownloadState state) |
+ int64 num_files) |
: url_(url), |
path_(path), |
- num_files_(num_files), |
- state_(state) {} |
+ num_files_(num_files) { |
+ } |
bool operator() (const DownloadPersistentStoreInfo& info) const { |
return info.url == url_ && |
@@ -282,37 +223,22 @@ |
((num_files_ < 0) || |
(info.received_bytes == num_files_)) && |
info.total_bytes == 0 && |
- info.state == state_; |
+ info.state == DownloadItem::COMPLETE; |
} |
GURL url_; |
FilePath path_; |
int64 num_files_; |
- DownloadItem::DownloadState state_; |
}; |
void CheckDownloadHistory(const GURL& url, |
const FilePath& path, |
- int64 num_files, |
- DownloadItem::DownloadState state) { |
- // Make sure the relevant download item made it into the history. |
- std::vector<DownloadItem*> downloads; |
- GetDownloadManager()->SearchDownloads(string16(), &downloads); |
- ASSERT_EQ(1u, downloads.size()); |
- DownloadPersistedObserver(downloads[0]).WaitForPersisted(); |
- |
- // Make sure any final updates have made it to the history DB. |
- BrowserThread::PostTaskAndReply( |
- BrowserThread::DB, FROM_HERE, base::Bind(&NullFunction), |
- MessageLoop::QuitClosure()); |
- content::RunMessageLoop(); |
- |
+ int64 num_files) { |
QueryDownloadHistory(); |
std::vector<DownloadPersistentStoreInfo>::iterator found = |
std::find_if(history_entries_.begin(), history_entries_.end(), |
- DownloadPersistentStoreInfoMatch(url, path, num_files, |
- state)); |
+ DownloadPersistentStoreInfoMatch(url, path, num_files)); |
if (found == history_entries_.end()) { |
LOG(ERROR) << "Missing url=" << url.spec() |
@@ -356,8 +282,7 @@ |
EXPECT_EQ(url, WaitForSavePackageToFinish()); |
EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
- // a.htm is 1 file. |
- CheckDownloadHistory(url, full_file_name, 1, DownloadItem::COMPLETE); |
+ CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. |
EXPECT_TRUE(file_util::PathExists(full_file_name)); |
EXPECT_FALSE(file_util::PathExists(dir)); |
@@ -385,12 +310,8 @@ |
// Currently it's ignored. |
EXPECT_EQ(url, WaitForSavePackageToFinish()); |
- // -1 to disable number of files check; we don't update after cancel, and |
- // we don't know when the single file completed in relationship to |
- // the cancel. |
- CheckDownloadHistory(url, full_file_name, -1, DownloadItem::CANCELLED); |
- |
EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
+ CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. |
EXPECT_TRUE(file_util::PathExists(full_file_name)); |
EXPECT_FALSE(file_util::PathExists(dir)); |
@@ -439,9 +360,7 @@ |
EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); |
EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
- // a.htm is 1 file. |
- CheckDownloadHistory(actual_page_url, full_file_name, 1, |
- DownloadItem::COMPLETE); |
+ CheckDownloadHistory(actual_page_url, full_file_name, 1); // a.htm is 1 file. |
EXPECT_TRUE(file_util::PathExists(full_file_name)); |
EXPECT_FALSE(file_util::PathExists(dir)); |
@@ -461,8 +380,7 @@ |
EXPECT_EQ(url, WaitForSavePackageToFinish()); |
EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
- // b.htm is 3 files. |
- CheckDownloadHistory(url, full_file_name, 3, DownloadItem::COMPLETE); |
+ CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. |
EXPECT_TRUE(file_util::PathExists(full_file_name)); |
EXPECT_TRUE(file_util::PathExists(dir)); |
@@ -495,8 +413,7 @@ |
EXPECT_EQ(url, WaitForSavePackageToFinish()); |
EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
- // b.htm is 3 files. |
- CheckDownloadHistory(url, full_file_name, 3, DownloadItem::COMPLETE); |
+ CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. |
EXPECT_TRUE(file_util::PathExists(full_file_name)); |
EXPECT_TRUE(file_util::PathExists(dir)); |
@@ -522,16 +439,14 @@ |
EXPECT_EQ(url, WaitForSavePackageToFinish()); |
EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
- // a.htm is 1 file. |
- CheckDownloadHistory(url, full_file_name, 1, DownloadItem::COMPLETE); |
+ CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. |
EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); |
// Should not be in history. |
QueryDownloadHistory(); |
EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(), |
- DownloadPersistentStoreInfoMatch( |
- url, full_file_name, 1, DownloadItem::COMPLETE)), |
+ DownloadPersistentStoreInfoMatch(url, full_file_name, 1)), |
history_entries_.end()); |
EXPECT_TRUE(file_util::PathExists(full_file_name)); |
@@ -605,7 +520,7 @@ |
content::NotificationService::AllSources()); |
chrome::SavePage(browser()); |
observer.Wait(); |
- CheckDownloadHistory(url, full_file_name, -1, DownloadItem::COMPLETE); |
+ CheckDownloadHistory(url, full_file_name, -1); |
EXPECT_TRUE(file_util::PathExists(full_file_name)); |
int64 actual_file_size = -1; |