| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 21 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 22 #include "chrome/browser/download/download_crx_util.h" | 22 #include "chrome/browser/download/download_crx_util.h" |
| 23 #include "chrome/browser/download/download_history.h" | 23 #include "chrome/browser/download/download_history.h" |
| 24 #include "chrome/browser/download/download_prefs.h" | 24 #include "chrome/browser/download/download_prefs.h" |
| 25 #include "chrome/browser/download/download_request_limiter.h" | 25 #include "chrome/browser/download/download_request_limiter.h" |
| 26 #include "chrome/browser/download/download_shelf.h" | 26 #include "chrome/browser/download/download_shelf.h" |
| 27 #include "chrome/browser/download/download_test_file_chooser_observer.h" | 27 #include "chrome/browser/download/download_test_file_chooser_observer.h" |
| 28 #include "chrome/browser/download/download_util.h" | 28 #include "chrome/browser/download/download_util.h" |
| 29 #include "chrome/browser/extensions/extension_install_prompt.h" | 29 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 30 #include "chrome/browser/extensions/extension_service.h" | 30 #include "chrome/browser/extensions/extension_service.h" |
| 31 #include "chrome/browser/history/download_persistent_store_info.h" |
| 31 #include "chrome/browser/history/history.h" | 32 #include "chrome/browser/history/history.h" |
| 32 #include "chrome/browser/history/history_service_factory.h" | 33 #include "chrome/browser/history/history_service_factory.h" |
| 33 #include "chrome/browser/net/url_request_mock_util.h" | 34 #include "chrome/browser/net/url_request_mock_util.h" |
| 34 #include "chrome/browser/prefs/pref_service.h" | 35 #include "chrome/browser/prefs/pref_service.h" |
| 35 #include "chrome/browser/profiles/profile.h" | 36 #include "chrome/browser/profiles/profile.h" |
| 36 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 37 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 37 #include "chrome/browser/ui/browser.h" | 38 #include "chrome/browser/ui/browser.h" |
| 38 #include "chrome/browser/ui/browser_commands.h" | 39 #include "chrome/browser/ui/browser_commands.h" |
| 39 #include "chrome/browser/ui/browser_list.h" | 40 #include "chrome/browser/ui/browser_list.h" |
| 40 #include "chrome/browser/ui/browser_tabstrip.h" | 41 #include "chrome/browser/ui/browser_tabstrip.h" |
| 41 #include "chrome/browser/ui/browser_window.h" | 42 #include "chrome/browser/ui/browser_window.h" |
| 42 #include "chrome/browser/ui/chrome_pages.h" | 43 #include "chrome/browser/ui/chrome_pages.h" |
| 43 #include "chrome/common/chrome_notification_types.h" | 44 #include "chrome/common/chrome_notification_types.h" |
| 44 #include "chrome/common/chrome_paths.h" | 45 #include "chrome/common/chrome_paths.h" |
| 45 #include "chrome/common/extensions/extension_switch_utils.h" | 46 #include "chrome/common/extensions/extension_switch_utils.h" |
| 46 #include "chrome/common/pref_names.h" | 47 #include "chrome/common/pref_names.h" |
| 47 #include "chrome/common/url_constants.h" | 48 #include "chrome/common/url_constants.h" |
| 48 #include "chrome/test/base/in_process_browser_test.h" | 49 #include "chrome/test/base/in_process_browser_test.h" |
| 49 #include "chrome/test/base/ui_test_utils.h" | 50 #include "chrome/test/base/ui_test_utils.h" |
| 50 #include "content/public/browser/download_item.h" | 51 #include "content/public/browser/download_item.h" |
| 51 #include "content/public/browser/download_manager.h" | 52 #include "content/public/browser/download_manager.h" |
| 52 #include "content/public/browser/download_persistent_store_info.h" | |
| 53 #include "content/public/browser/download_save_info.h" | 53 #include "content/public/browser/download_save_info.h" |
| 54 #include "content/public/browser/download_url_parameters.h" | 54 #include "content/public/browser/download_url_parameters.h" |
| 55 #include "content/public/browser/notification_source.h" | 55 #include "content/public/browser/notification_source.h" |
| 56 #include "content/public/browser/render_view_host.h" | 56 #include "content/public/browser/render_view_host.h" |
| 57 #include "content/public/browser/resource_context.h" | 57 #include "content/public/browser/resource_context.h" |
| 58 #include "content/public/browser/web_contents.h" | 58 #include "content/public/browser/web_contents.h" |
| 59 #include "content/public/common/context_menu_params.h" | 59 #include "content/public/common/context_menu_params.h" |
| 60 #include "content/public/common/page_transition_types.h" | 60 #include "content/public/common/page_transition_types.h" |
| 61 #include "content/public/test/browser_test_utils.h" | 61 #include "content/public/test/browser_test_utils.h" |
| 62 #include "content/public/test/download_test_observer.h" | 62 #include "content/public/test/download_test_observer.h" |
| 63 #include "content/public/test/test_file_error_injector.h" | 63 #include "content/public/test/test_file_error_injector.h" |
| 64 #include "content/public/test/test_navigation_observer.h" | 64 #include "content/public/test/test_navigation_observer.h" |
| 65 #include "content/test/net/url_request_mock_http_job.h" | 65 #include "content/test/net/url_request_mock_http_job.h" |
| 66 #include "content/test/net/url_request_slow_download_job.h" | 66 #include "content/test/net/url_request_slow_download_job.h" |
| 67 #include "net/base/net_util.h" | 67 #include "net/base/net_util.h" |
| 68 #include "net/test/test_server.h" | 68 #include "net/test/test_server.h" |
| 69 #include "testing/gtest/include/gtest/gtest.h" | 69 #include "testing/gtest/include/gtest/gtest.h" |
| 70 | 70 |
| 71 using content::BrowserContext; | 71 using content::BrowserContext; |
| 72 using content::BrowserThread; | 72 using content::BrowserThread; |
| 73 using content::DownloadItem; | 73 using content::DownloadItem; |
| 74 using content::DownloadManager; | 74 using content::DownloadManager; |
| 75 using content::DownloadPersistentStoreInfo; | |
| 76 using content::DownloadUrlParameters; | 75 using content::DownloadUrlParameters; |
| 77 using content::WebContents; | 76 using content::WebContents; |
| 78 using extensions::Extension; | 77 using extensions::Extension; |
| 79 | 78 |
| 80 namespace { | 79 namespace { |
| 81 | 80 |
| 82 // IDs and paths of CRX files used in tests. | 81 // IDs and paths of CRX files used in tests. |
| 83 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 82 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 84 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); | 83 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); |
| 85 | 84 |
| 86 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; | 85 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
| 87 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); | 86 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); |
| 88 | 87 |
| 89 // Get History Information. | |
| 90 class DownloadsHistoryDataCollector { | |
| 91 public: | |
| 92 DownloadsHistoryDataCollector(int64 download_db_handle, | |
| 93 DownloadManager* manager) | |
| 94 : result_valid_(false), | |
| 95 download_db_handle_(download_db_handle) { | |
| 96 HistoryService* hs = HistoryServiceFactory::GetForProfile( | |
| 97 Profile::FromBrowserContext(manager->GetBrowserContext()), | |
| 98 Profile::EXPLICIT_ACCESS); | |
| 99 DCHECK(hs); | |
| 100 hs->QueryDownloads( | |
| 101 &callback_consumer_, | |
| 102 base::Bind(&DownloadsHistoryDataCollector::OnQueryDownloadsComplete, | |
| 103 base::Unretained(this))); | |
| 104 | |
| 105 // TODO(rdsmith): Move message loop out of constructor. | |
| 106 // Cannot complete immediately because the history backend runs on a | |
| 107 // separate thread, so we can assume that the RunMessageLoop below will | |
| 108 // be exited by the Quit in OnQueryDownloadsComplete. | |
| 109 content::RunMessageLoop(); | |
| 110 } | |
| 111 | |
| 112 bool GetDownloadsHistoryEntry(DownloadPersistentStoreInfo* result) { | |
| 113 DCHECK(result); | |
| 114 *result = result_; | |
| 115 return result_valid_; | |
| 116 } | |
| 117 | |
| 118 private: | |
| 119 void OnQueryDownloadsComplete( | |
| 120 std::vector<DownloadPersistentStoreInfo>* entries) { | |
| 121 result_valid_ = false; | |
| 122 for (std::vector<DownloadPersistentStoreInfo>::const_iterator it = | |
| 123 entries->begin(); | |
| 124 it != entries->end(); ++it) { | |
| 125 if (it->db_handle == download_db_handle_) { | |
| 126 result_ = *it; | |
| 127 result_valid_ = true; | |
| 128 } | |
| 129 } | |
| 130 MessageLoopForUI::current()->Quit(); | |
| 131 } | |
| 132 | |
| 133 DownloadPersistentStoreInfo result_; | |
| 134 bool result_valid_; | |
| 135 int64 download_db_handle_; | |
| 136 CancelableRequestConsumer callback_consumer_; | |
| 137 | |
| 138 DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector); | |
| 139 }; | |
| 140 | |
| 141 // Mock that simulates a permissions dialog where the user denies | 88 // Mock that simulates a permissions dialog where the user denies |
| 142 // permission to install. TODO(skerner): This could be shared with | 89 // permission to install. TODO(skerner): This could be shared with |
| 143 // extensions tests. Find a common place for this class. | 90 // extensions tests. Find a common place for this class. |
| 144 class MockAbortExtensionInstallPrompt : public ExtensionInstallPrompt { | 91 class MockAbortExtensionInstallPrompt : public ExtensionInstallPrompt { |
| 145 public: | 92 public: |
| 146 MockAbortExtensionInstallPrompt() : ExtensionInstallPrompt(NULL, NULL, NULL) { | 93 MockAbortExtensionInstallPrompt() : ExtensionInstallPrompt(NULL, NULL, NULL) { |
| 147 } | 94 } |
| 148 | 95 |
| 149 // Simulate a user abort on an extension installation. | 96 // Simulate a user abort on an extension installation. |
| 150 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { | 97 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 private: | 137 private: |
| 191 virtual void PlatformInit() {} | 138 virtual void PlatformInit() {} |
| 192 virtual void PlatformCancel() {} | 139 virtual void PlatformCancel() {} |
| 193 virtual bool GetAcceleratorForCommandId(int, ui::Accelerator*) { | 140 virtual bool GetAcceleratorForCommandId(int, ui::Accelerator*) { |
| 194 return false; | 141 return false; |
| 195 } | 142 } |
| 196 | 143 |
| 197 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); | 144 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); |
| 198 }; | 145 }; |
| 199 | 146 |
| 147 typedef std::vector<DownloadPersistentStoreInfo> InfoVector; |
| 148 |
| 149 void HistoryQueryCallbackOnUI( |
| 150 InfoVector* out, |
| 151 scoped_ptr<InfoVector> in) { |
| 152 in->swap(*out); |
| 153 MessageLoop::current()->Quit(); |
| 154 } |
| 155 |
| 156 void HistoryQueryCallbackOnDB( |
| 157 InfoVector* out, |
| 158 scoped_ptr<InfoVector> in) { |
| 159 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 160 base::Bind(&HistoryQueryCallbackOnUI, out, base::Passed(in.Pass()))); |
| 161 } |
| 162 |
| 200 } // namespace | 163 } // namespace |
| 201 | 164 |
| 202 // While an object of this class exists, it will mock out download | 165 // While an object of this class exists, it will mock out download |
| 203 // opening for all downloads created on the specified download manager. | 166 // opening for all downloads created on the specified download manager. |
| 204 class MockDownloadOpeningObserver : public DownloadManager::Observer { | 167 class MockDownloadOpeningObserver : public DownloadManager::Observer { |
| 205 public: | 168 public: |
| 206 explicit MockDownloadOpeningObserver(DownloadManager* manager) | 169 explicit MockDownloadOpeningObserver(DownloadManager* manager) |
| 207 : download_manager_(manager) { | 170 : download_manager_(manager) { |
| 208 download_manager_->AddObserver(this); | 171 download_manager_->AddObserver(this); |
| 209 } | 172 } |
| (...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 ExpectWindowCountAfterDownload(1); | 1363 ExpectWindowCountAfterDownload(1); |
| 1401 #endif | 1364 #endif |
| 1402 | 1365 |
| 1403 EXPECT_EQ(1, browser()->tab_count()); | 1366 EXPECT_EQ(1, browser()->tab_count()); |
| 1404 // Download shelf should close. Download panel stays open on ChromeOS. | 1367 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1405 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1368 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1406 | 1369 |
| 1407 CheckDownload(browser(), file, file); | 1370 CheckDownload(browser(), file, file); |
| 1408 } | 1371 } |
| 1409 | 1372 |
| 1410 // Confirm a download makes it into the history properly. | |
| 1411 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { | |
| 1412 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
| 1413 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1414 FilePath origin_file(OriginFile(file)); | |
| 1415 int64 origin_size; | |
| 1416 file_util::GetFileSize(origin_file, &origin_size); | |
| 1417 | |
| 1418 // Download the file and wait. We do not expect the Select File dialog. | |
| 1419 DownloadAndWait(browser(), url); | |
| 1420 | |
| 1421 // Get details of what downloads have just happened. | |
| 1422 std::vector<DownloadItem*> downloads; | |
| 1423 GetDownloads(browser(), &downloads); | |
| 1424 ASSERT_EQ(1u, downloads.size()); | |
| 1425 int64 db_handle = downloads[0]->GetDbHandle(); | |
| 1426 | |
| 1427 // Check state. | |
| 1428 EXPECT_EQ(1, browser()->tab_count()); | |
| 1429 CheckDownload(browser(), file, file); | |
| 1430 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | |
| 1431 | |
| 1432 // Check history results. | |
| 1433 DownloadsHistoryDataCollector history_collector( | |
| 1434 db_handle, | |
| 1435 DownloadManagerForBrowser(browser())); | |
| 1436 DownloadPersistentStoreInfo info; | |
| 1437 EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle; | |
| 1438 EXPECT_EQ(file, info.path.BaseName()); | |
| 1439 EXPECT_EQ(url, info.url); | |
| 1440 // Ignore start_time. | |
| 1441 EXPECT_EQ(origin_size, info.received_bytes); | |
| 1442 EXPECT_EQ(origin_size, info.total_bytes); | |
| 1443 EXPECT_EQ(DownloadItem::COMPLETE, info.state); | |
| 1444 } | |
| 1445 | |
| 1446 // Test for crbug.com/14505. This tests that chrome:// urls are still functional | 1373 // Test for crbug.com/14505. This tests that chrome:// urls are still functional |
| 1447 // after download of a file while viewing another chrome://. | 1374 // after download of a file while viewing another chrome://. |
| 1448 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { | 1375 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { |
| 1449 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1376 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1450 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1377 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1451 GURL flags_url(chrome::kChromeUIFlagsURL); | 1378 GURL flags_url(chrome::kChromeUIFlagsURL); |
| 1452 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); | 1379 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); |
| 1453 | 1380 |
| 1454 ui_test_utils::NavigateToURL(browser(), flags_url); | 1381 ui_test_utils::NavigateToURL(browser(), flags_url); |
| 1455 DownloadAndWait(browser(), download_url); | 1382 DownloadAndWait(browser(), download_url); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1687 | 1614 |
| 1688 // Download shelf should close. Download panel stays open on ChromeOS. | 1615 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1689 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1616 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1690 | 1617 |
| 1691 // Check that the extension was installed. | 1618 // Check that the extension was installed. |
| 1692 ExtensionService* extension_service = | 1619 ExtensionService* extension_service = |
| 1693 browser()->profile()->GetExtensionService(); | 1620 browser()->profile()->GetExtensionService(); |
| 1694 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 1621 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
| 1695 } | 1622 } |
| 1696 | 1623 |
| 1697 // Sort download items by db_handle. | 1624 // Sort download items by id. |
| 1698 static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) { | 1625 static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) { |
| 1699 return d1->GetDbHandle() < d2->GetDbHandle(); | 1626 return d1->GetId() < d2->GetId(); |
| 1700 } | 1627 } |
| 1701 | 1628 |
| 1702 // Confirm that searching through the history works properly | 1629 // Confirm that searching through the history works properly |
| 1703 IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) { | 1630 IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) { |
| 1704 // Downloads to populate history with. | |
| 1705 base::Time current(base::Time::Now()); | |
| 1706 DownloadPersistentStoreInfo population_entries[] = { | |
| 1707 DownloadPersistentStoreInfo( | |
| 1708 FilePath(FILE_PATH_LITERAL("/path/to/file")), | |
| 1709 GURL("http://www.google.com/fantasy_download"), | |
| 1710 GURL(""), | |
| 1711 current - base::TimeDelta::FromMinutes(5), | |
| 1712 current, | |
| 1713 128, | |
| 1714 128, | |
| 1715 DownloadItem::COMPLETE, | |
| 1716 1, | |
| 1717 false), | |
| 1718 DownloadPersistentStoreInfo( | |
| 1719 FilePath(FILE_PATH_LITERAL("/path/to/another_file")), | |
| 1720 GURL("http://www.google.com/reality_download"), | |
| 1721 GURL(""), | |
| 1722 current - base::TimeDelta::FromMinutes(10), | |
| 1723 current, | |
| 1724 256, | |
| 1725 256, | |
| 1726 DownloadItem::COMPLETE, | |
| 1727 2, | |
| 1728 false), | |
| 1729 DownloadPersistentStoreInfo( | |
| 1730 FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")), | |
| 1731 GURL("http://www.izzle.com/not_really_a_download"), | |
| 1732 GURL(""), | |
| 1733 current - base::TimeDelta::FromMinutes(15), | |
| 1734 current, | |
| 1735 512, | |
| 1736 512, | |
| 1737 DownloadItem::COMPLETE, | |
| 1738 3, | |
| 1739 true) | |
| 1740 }; | |
| 1741 std::vector<DownloadPersistentStoreInfo> entries( | |
| 1742 population_entries, population_entries + arraysize(population_entries)); | |
| 1743 | |
| 1744 // Populate the manager. | 1631 // Populate the manager. |
| 1745 DownloadManager* manager = DownloadManagerForBrowser(browser()); | 1632 DownloadManager* manager = DownloadManagerForBrowser(browser()); |
| 1746 manager->OnPersistentStoreQueryComplete(&entries); | 1633 base::Time current(base::Time::Now()); |
| 1634 manager->CreateDownloadItem( |
| 1635 FilePath(FILE_PATH_LITERAL("/path/to/file")), |
| 1636 GURL("http://www.google.com/fantasy_download"), |
| 1637 GURL(""), |
| 1638 current - base::TimeDelta::FromMinutes(5), |
| 1639 current, |
| 1640 128, |
| 1641 128, |
| 1642 DownloadItem::COMPLETE, |
| 1643 false); |
| 1644 manager->CreateDownloadItem( |
| 1645 FilePath(FILE_PATH_LITERAL("/path/to/another_file")), |
| 1646 GURL("http://www.google.com/reality_download"), |
| 1647 GURL(""), |
| 1648 current - base::TimeDelta::FromMinutes(10), |
| 1649 current, |
| 1650 256, |
| 1651 256, |
| 1652 DownloadItem::COMPLETE, |
| 1653 false); |
| 1654 manager->CreateDownloadItem( |
| 1655 FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")), |
| 1656 GURL("http://www.izzle.com/not_really_a_download"), |
| 1657 GURL(""), |
| 1658 current - base::TimeDelta::FromMinutes(15), |
| 1659 current, |
| 1660 512, |
| 1661 512, |
| 1662 DownloadItem::COMPLETE, |
| 1663 true); |
| 1747 | 1664 |
| 1748 // Do some searches and check the results. | 1665 // Do some searches and check the results. |
| 1749 std::vector<DownloadItem*> search_results; | 1666 std::vector<DownloadItem*> search_results; |
| 1750 | 1667 |
| 1751 manager->SearchDownloads(string16(), &search_results); | 1668 manager->SearchDownloads(string16(), &search_results); |
| 1752 ASSERT_EQ(3u, search_results.size()); | 1669 ASSERT_EQ(3u, search_results.size()); |
| 1753 std::sort(search_results.begin(), search_results.end(), | 1670 std::sort(search_results.begin(), search_results.end(), |
| 1754 DownloadItemSorter); | 1671 DownloadItemSorter); |
| 1755 // We do a full check only once to protect against the data | 1672 // We do a full check only once to protect against the data |
| 1756 // somehow getting scrambled on its way into the DownloadItems. | 1673 // somehow getting scrambled on its way into the DownloadItems. |
| 1757 { | 1674 { |
| 1758 DownloadItem* d1 = search_results[0]; | 1675 DownloadItem* d1 = search_results[0]; |
| 1759 DownloadItem* d2 = search_results[1]; | 1676 DownloadItem* d2 = search_results[1]; |
| 1760 DownloadItem* d3 = search_results[2]; | 1677 DownloadItem* d3 = search_results[2]; |
| 1761 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/file")), d1->GetFullPath()); | 1678 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/file")), d1->GetFullPath()); |
| 1762 EXPECT_EQ(GURL("http://www.google.com/fantasy_download"), | 1679 EXPECT_EQ(GURL("http://www.google.com/fantasy_download"), |
| 1763 d1->GetOriginalUrl()); | 1680 d1->GetOriginalUrl()); |
| 1764 EXPECT_EQ(current - base::TimeDelta::FromMinutes(5), | 1681 EXPECT_EQ(current - base::TimeDelta::FromMinutes(5), |
| 1765 d1->GetStartTime()); | 1682 d1->GetStartTime()); |
| 1766 EXPECT_EQ(current, d1->GetEndTime()); | 1683 EXPECT_EQ(current, d1->GetEndTime()); |
| 1767 EXPECT_EQ(128, d1->GetReceivedBytes()); | 1684 EXPECT_EQ(128, d1->GetReceivedBytes()); |
| 1768 EXPECT_EQ(128, d1->GetTotalBytes()); | 1685 EXPECT_EQ(128, d1->GetTotalBytes()); |
| 1769 EXPECT_EQ(DownloadItem::COMPLETE, d1->GetState()); | 1686 EXPECT_EQ(DownloadItem::COMPLETE, d1->GetState()); |
| 1770 EXPECT_EQ(1, d1->GetDbHandle()); | |
| 1771 EXPECT_FALSE(d1->GetOpened()); | 1687 EXPECT_FALSE(d1->GetOpened()); |
| 1772 | 1688 |
| 1773 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/another_file")), | 1689 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/another_file")), |
| 1774 d2->GetFullPath()); | 1690 d2->GetFullPath()); |
| 1775 EXPECT_EQ(GURL("http://www.google.com/reality_download"), | 1691 EXPECT_EQ(GURL("http://www.google.com/reality_download"), |
| 1776 d2->GetOriginalUrl()); | 1692 d2->GetOriginalUrl()); |
| 1777 EXPECT_EQ(current - base::TimeDelta::FromMinutes(10), | 1693 EXPECT_EQ(current - base::TimeDelta::FromMinutes(10), |
| 1778 d2->GetStartTime()); | 1694 d2->GetStartTime()); |
| 1779 EXPECT_EQ(current, d2->GetEndTime()); | 1695 EXPECT_EQ(current, d2->GetEndTime()); |
| 1780 EXPECT_EQ(256, d2->GetReceivedBytes()); | 1696 EXPECT_EQ(256, d2->GetReceivedBytes()); |
| 1781 EXPECT_EQ(256, d2->GetTotalBytes()); | 1697 EXPECT_EQ(256, d2->GetTotalBytes()); |
| 1782 EXPECT_EQ(DownloadItem::COMPLETE, d2->GetState()); | 1698 EXPECT_EQ(DownloadItem::COMPLETE, d2->GetState()); |
| 1783 EXPECT_EQ(2, d2->GetDbHandle()); | |
| 1784 EXPECT_FALSE(d2->GetOpened()); | 1699 EXPECT_FALSE(d2->GetOpened()); |
| 1785 | 1700 |
| 1786 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")), | 1701 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")), |
| 1787 d3->GetFullPath()); | 1702 d3->GetFullPath()); |
| 1788 EXPECT_EQ(GURL("http://www.izzle.com/not_really_a_download"), | 1703 EXPECT_EQ(GURL("http://www.izzle.com/not_really_a_download"), |
| 1789 d3->GetOriginalUrl()); | 1704 d3->GetOriginalUrl()); |
| 1790 EXPECT_EQ(current - base::TimeDelta::FromMinutes(15), | 1705 EXPECT_EQ(current - base::TimeDelta::FromMinutes(15), |
| 1791 d3->GetStartTime()); | 1706 d3->GetStartTime()); |
| 1792 EXPECT_EQ(current, d3->GetEndTime()); | 1707 EXPECT_EQ(current, d3->GetEndTime()); |
| 1793 EXPECT_EQ(512, d3->GetReceivedBytes()); | 1708 EXPECT_EQ(512, d3->GetReceivedBytes()); |
| 1794 EXPECT_EQ(512, d3->GetTotalBytes()); | 1709 EXPECT_EQ(512, d3->GetTotalBytes()); |
| 1795 EXPECT_EQ(DownloadItem::COMPLETE, d3->GetState()); | 1710 EXPECT_EQ(DownloadItem::COMPLETE, d3->GetState()); |
| 1796 EXPECT_EQ(3, d3->GetDbHandle()); | |
| 1797 EXPECT_TRUE(d3->GetOpened()); | 1711 EXPECT_TRUE(d3->GetOpened()); |
| 1798 } | 1712 } |
| 1799 search_results.clear(); | 1713 search_results.clear(); |
| 1800 | 1714 |
| 1801 string16 search_input; | 1715 string16 search_input; |
| 1802 manager->SearchDownloads(UTF8ToUTF16("www.google.com"), &search_results); | 1716 manager->SearchDownloads(UTF8ToUTF16("www.google.com"), &search_results); |
| 1803 ASSERT_EQ(2u, search_results.size()); | 1717 ASSERT_EQ(2u, search_results.size()); |
| 1804 std::sort(search_results.begin(), search_results.end(), | 1718 std::sort(search_results.begin(), search_results.end(), |
| 1805 DownloadItemSorter); | 1719 DownloadItemSorter); |
| 1806 EXPECT_EQ(1, search_results[0]->GetDbHandle()); | |
| 1807 EXPECT_EQ(2, search_results[1]->GetDbHandle()); | |
| 1808 search_results.clear(); | 1720 search_results.clear(); |
| 1809 | 1721 |
| 1810 manager->SearchDownloads(UTF8ToUTF16("real"), &search_results); | 1722 manager->SearchDownloads(UTF8ToUTF16("real"), &search_results); |
| 1811 ASSERT_EQ(2u, search_results.size()); | 1723 ASSERT_EQ(2u, search_results.size()); |
| 1812 std::sort(search_results.begin(), search_results.end(), | 1724 std::sort(search_results.begin(), search_results.end(), |
| 1813 DownloadItemSorter); | 1725 DownloadItemSorter); |
| 1814 EXPECT_EQ(2, search_results[0]->GetDbHandle()); | |
| 1815 EXPECT_EQ(3, search_results[1]->GetDbHandle()); | |
| 1816 search_results.clear(); | 1726 search_results.clear(); |
| 1817 | 1727 |
| 1818 manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results); | 1728 manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results); |
| 1819 ASSERT_EQ(2u, search_results.size()); | 1729 ASSERT_EQ(2u, search_results.size()); |
| 1820 std::sort(search_results.begin(), search_results.end(), | 1730 std::sort(search_results.begin(), search_results.end(), |
| 1821 DownloadItemSorter); | 1731 DownloadItemSorter); |
| 1822 EXPECT_EQ(2, search_results[0]->GetDbHandle()); | |
| 1823 EXPECT_EQ(3, search_results[1]->GetDbHandle()); | |
| 1824 search_results.clear(); | 1732 search_results.clear(); |
| 1825 } | 1733 } |
| 1826 | 1734 |
| 1827 // Tests for download initiation functions. | 1735 // Tests for download initiation functions. |
| 1828 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { | 1736 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { |
| 1829 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1737 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1830 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1738 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1831 | 1739 |
| 1832 // DownloadUrl always prompts; return acceptance of whatever it prompts. | 1740 // DownloadUrl always prompts; return acceptance of whatever it prompts. |
| 1833 EnableFileChooser(true); | 1741 EnableFileChooser(true); |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2347 GetDownloads(browser(), &download_items); | 2255 GetDownloads(browser(), &download_items); |
| 2348 ASSERT_EQ(1u, download_items.size()); | 2256 ASSERT_EQ(1u, download_items.size()); |
| 2349 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), | 2257 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), |
| 2350 download_items[0]->GetOriginalUrl()); | 2258 download_items[0]->GetOriginalUrl()); |
| 2351 | 2259 |
| 2352 // Check that the file contains the expected referrer. | 2260 // Check that the file contains the expected referrer. |
| 2353 FilePath file(download_items[0]->GetFullPath()); | 2261 FilePath file(download_items[0]->GetFullPath()); |
| 2354 std::string expected_contents = test_server()->GetURL("").spec(); | 2262 std::string expected_contents = test_server()->GetURL("").spec(); |
| 2355 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); | 2263 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); |
| 2356 } | 2264 } |
| OLD | NEW |