Index: chrome/browser/download/download_browsertest.cc |
diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc |
index 21c0f3c2226703a6d26c8baf73e0ff90e27bc39b..080316b66b667eb362ba890fc3a2b98152d72121 100644 |
--- a/chrome/browser/download/download_browsertest.cc |
+++ b/chrome/browser/download/download_browsertest.cc |
@@ -28,6 +28,7 @@ |
#include "chrome/browser/download/download_util.h" |
#include "chrome/browser/extensions/extension_install_prompt.h" |
#include "chrome/browser/extensions/extension_service.h" |
+#include "chrome/browser/history/download_persistent_store_info.h" |
#include "chrome/browser/history/history.h" |
#include "chrome/browser/history/history_service_factory.h" |
#include "chrome/browser/net/url_request_mock_util.h" |
@@ -49,7 +50,6 @@ |
#include "chrome/test/base/ui_test_utils.h" |
#include "content/public/browser/download_item.h" |
#include "content/public/browser/download_manager.h" |
-#include "content/public/browser/download_persistent_store_info.h" |
#include "content/public/browser/download_save_info.h" |
#include "content/public/browser/download_url_parameters.h" |
#include "content/public/browser/notification_source.h" |
@@ -72,7 +72,6 @@ using content::BrowserContext; |
using content::BrowserThread; |
using content::DownloadItem; |
using content::DownloadManager; |
-using content::DownloadPersistentStoreInfo; |
using content::DownloadUrlParameters; |
using content::WebContents; |
using extensions::Extension; |
@@ -86,58 +85,6 @@ const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); |
const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); |
-// Get History Information. |
-class DownloadsHistoryDataCollector { |
- public: |
- DownloadsHistoryDataCollector(int64 download_db_handle, |
- DownloadManager* manager) |
- : result_valid_(false), |
- download_db_handle_(download_db_handle) { |
- HistoryService* hs = HistoryServiceFactory::GetForProfile( |
- Profile::FromBrowserContext(manager->GetBrowserContext()), |
- Profile::EXPLICIT_ACCESS); |
- DCHECK(hs); |
- hs->QueryDownloads( |
- &callback_consumer_, |
- base::Bind(&DownloadsHistoryDataCollector::OnQueryDownloadsComplete, |
- base::Unretained(this))); |
- |
- // TODO(rdsmith): Move message loop out of constructor. |
- // Cannot complete immediately because the history backend runs on a |
- // separate thread, so we can assume that the RunMessageLoop below will |
- // be exited by the Quit in OnQueryDownloadsComplete. |
- content::RunMessageLoop(); |
- } |
- |
- bool GetDownloadsHistoryEntry(DownloadPersistentStoreInfo* result) { |
- DCHECK(result); |
- *result = result_; |
- return result_valid_; |
- } |
- |
- private: |
- void OnQueryDownloadsComplete( |
- std::vector<DownloadPersistentStoreInfo>* entries) { |
- result_valid_ = false; |
- for (std::vector<DownloadPersistentStoreInfo>::const_iterator it = |
- entries->begin(); |
- it != entries->end(); ++it) { |
- if (it->db_handle == download_db_handle_) { |
- result_ = *it; |
- result_valid_ = true; |
- } |
- } |
- MessageLoopForUI::current()->Quit(); |
- } |
- |
- DownloadPersistentStoreInfo result_; |
- bool result_valid_; |
- int64 download_db_handle_; |
- CancelableRequestConsumer callback_consumer_; |
- |
- DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector); |
-}; |
- |
// Mock that simulates a permissions dialog where the user denies |
// permission to install. TODO(skerner): This could be shared with |
// extensions tests. Find a common place for this class. |
@@ -197,6 +144,22 @@ class TestRenderViewContextMenu : public RenderViewContextMenu { |
DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); |
}; |
+typedef std::vector<DownloadPersistentStoreInfo> InfoVector; |
+ |
+void HistoryQueryCallbackOnUI( |
+ InfoVector* out, |
+ scoped_ptr<InfoVector> in) { |
+ in->swap(*out); |
+ MessageLoop::current()->Quit(); |
+} |
+ |
+void HistoryQueryCallbackOnDB( |
+ InfoVector* out, |
+ scoped_ptr<InfoVector> in) { |
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
+ base::Bind(&HistoryQueryCallbackOnUI, out, base::Passed(in.Pass()))); |
+} |
+ |
} // namespace |
// While an object of this class exists, it will mock out download |
@@ -1407,42 +1370,6 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { |
CheckDownload(browser(), file, file); |
} |
-// Confirm a download makes it into the history properly. |
-IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { |
- FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
- GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
- FilePath origin_file(OriginFile(file)); |
- int64 origin_size; |
- file_util::GetFileSize(origin_file, &origin_size); |
- |
- // Download the file and wait. We do not expect the Select File dialog. |
- DownloadAndWait(browser(), url); |
- |
- // Get details of what downloads have just happened. |
- std::vector<DownloadItem*> downloads; |
- GetDownloads(browser(), &downloads); |
- ASSERT_EQ(1u, downloads.size()); |
- int64 db_handle = downloads[0]->GetDbHandle(); |
- |
- // Check state. |
- EXPECT_EQ(1, browser()->tab_count()); |
- CheckDownload(browser(), file, file); |
- EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
- |
- // Check history results. |
- DownloadsHistoryDataCollector history_collector( |
- db_handle, |
- DownloadManagerForBrowser(browser())); |
- DownloadPersistentStoreInfo info; |
- EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle; |
- EXPECT_EQ(file, info.path.BaseName()); |
- EXPECT_EQ(url, info.url); |
- // Ignore start_time. |
- EXPECT_EQ(origin_size, info.received_bytes); |
- EXPECT_EQ(origin_size, info.total_bytes); |
- EXPECT_EQ(DownloadItem::COMPLETE, info.state); |
-} |
- |
// Test for crbug.com/14505. This tests that chrome:// urls are still functional |
// after download of a file while viewing another chrome://. |
IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { |
@@ -1693,56 +1620,46 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { |
ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
} |
-// Sort download items by db_handle. |
+// Sort download items by id. |
static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) { |
- return d1->GetDbHandle() < d2->GetDbHandle(); |
+ return d1->GetId() < d2->GetId(); |
} |
// Confirm that searching through the history works properly |
IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) { |
- // Downloads to populate history with. |
- base::Time current(base::Time::Now()); |
- DownloadPersistentStoreInfo population_entries[] = { |
- DownloadPersistentStoreInfo( |
- FilePath(FILE_PATH_LITERAL("/path/to/file")), |
- GURL("http://www.google.com/fantasy_download"), |
- GURL(""), |
- current - base::TimeDelta::FromMinutes(5), |
- current, |
- 128, |
- 128, |
- DownloadItem::COMPLETE, |
- 1, |
- false), |
- DownloadPersistentStoreInfo( |
- FilePath(FILE_PATH_LITERAL("/path/to/another_file")), |
- GURL("http://www.google.com/reality_download"), |
- GURL(""), |
- current - base::TimeDelta::FromMinutes(10), |
- current, |
- 256, |
- 256, |
- DownloadItem::COMPLETE, |
- 2, |
- false), |
- DownloadPersistentStoreInfo( |
- FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")), |
- GURL("http://www.izzle.com/not_really_a_download"), |
- GURL(""), |
- current - base::TimeDelta::FromMinutes(15), |
- current, |
- 512, |
- 512, |
- DownloadItem::COMPLETE, |
- 3, |
- true) |
- }; |
- std::vector<DownloadPersistentStoreInfo> entries( |
- population_entries, population_entries + arraysize(population_entries)); |
- |
// Populate the manager. |
DownloadManager* manager = DownloadManagerForBrowser(browser()); |
- manager->OnPersistentStoreQueryComplete(&entries); |
+ base::Time current(base::Time::Now()); |
+ manager->CreateDownloadItem( |
+ FilePath(FILE_PATH_LITERAL("/path/to/file")), |
+ GURL("http://www.google.com/fantasy_download"), |
+ GURL(""), |
+ current - base::TimeDelta::FromMinutes(5), |
+ current, |
+ 128, |
+ 128, |
+ DownloadItem::COMPLETE, |
+ false); |
+ manager->CreateDownloadItem( |
+ FilePath(FILE_PATH_LITERAL("/path/to/another_file")), |
+ GURL("http://www.google.com/reality_download"), |
+ GURL(""), |
+ current - base::TimeDelta::FromMinutes(10), |
+ current, |
+ 256, |
+ 256, |
+ DownloadItem::COMPLETE, |
+ false); |
+ manager->CreateDownloadItem( |
+ FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")), |
+ GURL("http://www.izzle.com/not_really_a_download"), |
+ GURL(""), |
+ current - base::TimeDelta::FromMinutes(15), |
+ current, |
+ 512, |
+ 512, |
+ DownloadItem::COMPLETE, |
+ true); |
// Do some searches and check the results. |
std::vector<DownloadItem*> search_results; |
@@ -1766,7 +1683,6 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) { |
EXPECT_EQ(128, d1->GetReceivedBytes()); |
EXPECT_EQ(128, d1->GetTotalBytes()); |
EXPECT_EQ(DownloadItem::COMPLETE, d1->GetState()); |
- EXPECT_EQ(1, d1->GetDbHandle()); |
EXPECT_FALSE(d1->GetOpened()); |
EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/another_file")), |
@@ -1779,7 +1695,6 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) { |
EXPECT_EQ(256, d2->GetReceivedBytes()); |
EXPECT_EQ(256, d2->GetTotalBytes()); |
EXPECT_EQ(DownloadItem::COMPLETE, d2->GetState()); |
- EXPECT_EQ(2, d2->GetDbHandle()); |
EXPECT_FALSE(d2->GetOpened()); |
EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")), |
@@ -1792,7 +1707,6 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) { |
EXPECT_EQ(512, d3->GetReceivedBytes()); |
EXPECT_EQ(512, d3->GetTotalBytes()); |
EXPECT_EQ(DownloadItem::COMPLETE, d3->GetState()); |
- EXPECT_EQ(3, d3->GetDbHandle()); |
EXPECT_TRUE(d3->GetOpened()); |
} |
search_results.clear(); |
@@ -1802,24 +1716,18 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) { |
ASSERT_EQ(2u, search_results.size()); |
std::sort(search_results.begin(), search_results.end(), |
DownloadItemSorter); |
- EXPECT_EQ(1, search_results[0]->GetDbHandle()); |
- EXPECT_EQ(2, search_results[1]->GetDbHandle()); |
search_results.clear(); |
manager->SearchDownloads(UTF8ToUTF16("real"), &search_results); |
ASSERT_EQ(2u, search_results.size()); |
std::sort(search_results.begin(), search_results.end(), |
DownloadItemSorter); |
- EXPECT_EQ(2, search_results[0]->GetDbHandle()); |
- EXPECT_EQ(3, search_results[1]->GetDbHandle()); |
search_results.clear(); |
manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results); |
ASSERT_EQ(2u, search_results.size()); |
std::sort(search_results.begin(), search_results.end(), |
DownloadItemSorter); |
- EXPECT_EQ(2, search_results[0]->GetDbHandle()); |
- EXPECT_EQ(3, search_results[1]->GetDbHandle()); |
search_results.clear(); |
} |