| 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" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/test/test_file_util.h" | 16 #include "base/test/test_file_util.h" |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "chrome/app/chrome_command_ids.h" | 18 #include "chrome/app/chrome_command_ids.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/cancelable_request.h" | 20 #include "chrome/browser/cancelable_request.h" |
| 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_persistent_store_info.h" |
| 24 #include "chrome/browser/download/download_prefs.h" | 25 #include "chrome/browser/download/download_prefs.h" |
| 25 #include "chrome/browser/download/download_request_limiter.h" | 26 #include "chrome/browser/download/download_request_limiter.h" |
| 26 #include "chrome/browser/download/download_shelf.h" | 27 #include "chrome/browser/download/download_shelf.h" |
| 27 #include "chrome/browser/download/download_test_file_chooser_observer.h" | 28 #include "chrome/browser/download/download_test_file_chooser_observer.h" |
| 28 #include "chrome/browser/download/download_util.h" | 29 #include "chrome/browser/download/download_util.h" |
| 29 #include "chrome/browser/extensions/extension_install_prompt.h" | 30 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 30 #include "chrome/browser/extensions/extension_service.h" | 31 #include "chrome/browser/extensions/extension_service.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 HistoryQueryCallback( |
| 150 InfoVector* out, |
| 151 InfoVector* in) { |
| 152 in->swap(*out); |
| 153 MessageLoop::current()->Quit(); |
| 154 } |
| 155 |
| 200 } // namespace | 156 } // namespace |
| 201 | 157 |
| 202 // While an object of this class exists, it will mock out download | 158 // While an object of this class exists, it will mock out download |
| 203 // opening for all downloads created on the specified download manager. | 159 // opening for all downloads created on the specified download manager. |
| 204 class MockDownloadOpeningObserver : public DownloadManager::Observer { | 160 class MockDownloadOpeningObserver : public DownloadManager::Observer { |
| 205 public: | 161 public: |
| 206 explicit MockDownloadOpeningObserver(DownloadManager* manager) | 162 explicit MockDownloadOpeningObserver(DownloadManager* manager) |
| 207 : download_manager_(manager) { | 163 : download_manager_(manager) { |
| 208 download_manager_->AddObserver(this); | 164 download_manager_->AddObserver(this); |
| 209 } | 165 } |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 | 814 |
| 859 // Download the file and wait. We do not expect the Select File dialog. | 815 // Download the file and wait. We do not expect the Select File dialog. |
| 860 DownloadAndWait(browser(), url); | 816 DownloadAndWait(browser(), url); |
| 861 | 817 |
| 862 // Check state. | 818 // Check state. |
| 863 EXPECT_EQ(1, browser()->tab_count()); | 819 EXPECT_EQ(1, browser()->tab_count()); |
| 864 CheckDownload(browser(), file, file); | 820 CheckDownload(browser(), file, file); |
| 865 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 821 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
| 866 } | 822 } |
| 867 | 823 |
| 824 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistory) { |
| 825 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 826 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 827 HistoryService* hs = HistoryServiceFactory::GetForProfile( |
| 828 browser()->profile(), Profile::EXPLICIT_ACCESS); |
| 829 CancelableRequestConsumer history_consumer; |
| 830 InfoVector infos; |
| 831 hs->QueryDownloads(&history_consumer, base::Bind( |
| 832 &HistoryQueryCallback, &infos)); |
| 833 MessageLoop::current()->Run(); |
| 834 EXPECT_EQ(0, static_cast<int>(infos.size())); |
| 835 |
| 836 // Download the file and wait. We do not expect the Select File dialog. |
| 837 DownloadAndWait(browser(), url); |
| 838 CheckDownload(browser(), file, file); |
| 839 |
| 840 DownloadManager* manager = DownloadManagerForBrowser(browser()); |
| 841 DownloadManager::DownloadVector downloads; |
| 842 manager->SearchDownloads(string16(), &downloads); |
| 843 EXPECT_EQ(1, static_cast<int>(downloads.size())); |
| 844 |
| 845 hs->QueryDownloads(&history_consumer, base::Bind( |
| 846 &HistoryQueryCallback, &infos)); |
| 847 MessageLoop::current()->Run(); |
| 848 EXPECT_EQ(1, static_cast<int>(infos.size())); |
| 849 EXPECT_EQ(downloads[0]->GetFullPath().value(), infos[0].path.value()); |
| 850 EXPECT_EQ(url.spec(), infos[0].url.spec()); |
| 851 EXPECT_EQ("", infos[0].referrer_url.spec()); |
| 852 EXPECT_EQ(downloads[0]->GetStartTime().ToTimeT(), |
| 853 infos[0].start_time.ToTimeT()); |
| 854 EXPECT_EQ(downloads[0]->GetEndTime().ToTimeT(), infos[0].end_time.ToTimeT()); |
| 855 EXPECT_EQ(downloads[0]->GetReceivedBytes(), infos[0].received_bytes); |
| 856 EXPECT_EQ(downloads[0]->GetTotalBytes(), infos[0].total_bytes); |
| 857 EXPECT_EQ(DownloadItem::COMPLETE, infos[0].state); |
| 858 EXPECT_EQ(1, infos[0].db_handle); |
| 859 EXPECT_EQ(false, infos[0].opened); |
| 860 |
| 861 downloads[0]->MockDownloadOpenForTesting(); |
| 862 downloads[0]->OpenDownload(); |
| 863 EXPECT_TRUE(downloads[0]->GetOpened()); |
| 864 hs->QueryDownloads(&history_consumer, base::Bind( |
| 865 &HistoryQueryCallback, &infos)); |
| 866 MessageLoop::current()->Run(); |
| 867 EXPECT_EQ(1, static_cast<int>(infos.size())); |
| 868 EXPECT_EQ(1, infos[0].db_handle); |
| 869 EXPECT_EQ(true, infos[0].opened); |
| 870 } |
| 871 |
| 868 #if defined(OS_WIN) | 872 #if defined(OS_WIN) |
| 869 // Download a file and confirm that the zone identifier (on windows) | 873 // Download a file and confirm that the zone identifier (on windows) |
| 870 // is set to internet. | 874 // is set to internet. |
| 871 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { | 875 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { |
| 872 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 876 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 873 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 877 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 874 | 878 |
| 875 // Download the file and wait. We do not expect the Select File dialog. | 879 // Download the file and wait. We do not expect the Select File dialog. |
| 876 DownloadAndWait(browser(), url); | 880 DownloadAndWait(browser(), url); |
| 877 | 881 |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1522 | 1526 |
| 1523 // Get the important info from other threads and check it. | 1527 // Get the important info from other threads and check it. |
| 1524 EXPECT_TRUE(EnsureNoPendingDownloads()); | 1528 EXPECT_TRUE(EnsureNoPendingDownloads()); |
| 1525 | 1529 |
| 1526 // Using "DownloadItem::Remove" follows the discard dangerous download path, | 1530 // Using "DownloadItem::Remove" follows the discard dangerous download path, |
| 1527 // which completely removes the browser from the shelf and closes the shelf | 1531 // which completely removes the browser from the shelf and closes the shelf |
| 1528 // if it was there. Download panel stays open on ChromeOS. | 1532 // if it was there. Download panel stays open on ChromeOS. |
| 1529 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1533 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1530 } | 1534 } |
| 1531 | 1535 |
| 1532 // Confirm a download makes it into the history properly. | |
| 1533 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { | |
| 1534 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
| 1535 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1536 FilePath origin_file(OriginFile(file)); | |
| 1537 int64 origin_size; | |
| 1538 file_util::GetFileSize(origin_file, &origin_size); | |
| 1539 | |
| 1540 // Download the file and wait. We do not expect the Select File dialog. | |
| 1541 DownloadAndWait(browser(), url); | |
| 1542 | |
| 1543 // Get details of what downloads have just happened. | |
| 1544 std::vector<DownloadItem*> downloads; | |
| 1545 GetDownloads(browser(), &downloads); | |
| 1546 ASSERT_EQ(1u, downloads.size()); | |
| 1547 int64 db_handle = downloads[0]->GetDbHandle(); | |
| 1548 | |
| 1549 // Check state. | |
| 1550 EXPECT_EQ(1, browser()->tab_count()); | |
| 1551 CheckDownload(browser(), file, file); | |
| 1552 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | |
| 1553 | |
| 1554 // Check history results. | |
| 1555 DownloadsHistoryDataCollector history_collector( | |
| 1556 db_handle, | |
| 1557 DownloadManagerForBrowser(browser())); | |
| 1558 DownloadPersistentStoreInfo info; | |
| 1559 EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle; | |
| 1560 EXPECT_EQ(file, info.path.BaseName()); | |
| 1561 EXPECT_EQ(url, info.url); | |
| 1562 // Ignore start_time. | |
| 1563 EXPECT_EQ(origin_size, info.received_bytes); | |
| 1564 EXPECT_EQ(origin_size, info.total_bytes); | |
| 1565 EXPECT_EQ(DownloadItem::COMPLETE, info.state); | |
| 1566 } | |
| 1567 | |
| 1568 // Test for crbug.com/14505. This tests that chrome:// urls are still functional | 1536 // Test for crbug.com/14505. This tests that chrome:// urls are still functional |
| 1569 // after download of a file while viewing another chrome://. | 1537 // after download of a file while viewing another chrome://. |
| 1570 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { | 1538 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { |
| 1571 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1539 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1572 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1540 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1573 GURL flags_url(chrome::kChromeUIFlagsURL); | 1541 GURL flags_url(chrome::kChromeUIFlagsURL); |
| 1574 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); | 1542 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); |
| 1575 | 1543 |
| 1576 ui_test_utils::NavigateToURL(browser(), flags_url); | 1544 ui_test_utils::NavigateToURL(browser(), flags_url); |
| 1577 DownloadAndWait(browser(), download_url); | 1545 DownloadAndWait(browser(), download_url); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1809 | 1777 |
| 1810 // Download shelf should close. Download panel stays open on ChromeOS. | 1778 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1811 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1779 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 1812 | 1780 |
| 1813 // Check that the extension was installed. | 1781 // Check that the extension was installed. |
| 1814 ExtensionService* extension_service = | 1782 ExtensionService* extension_service = |
| 1815 browser()->profile()->GetExtensionService(); | 1783 browser()->profile()->GetExtensionService(); |
| 1816 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 1784 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
| 1817 } | 1785 } |
| 1818 | 1786 |
| 1819 // Sort download items by db_handle. | 1787 // Sort download items by id. |
| 1820 static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) { | 1788 static bool DownloadItemSorter(DownloadItem* d1, DownloadItem* d2) { |
| 1821 return d1->GetDbHandle() < d2->GetDbHandle(); | 1789 return d1->GetId() < d2->GetId(); |
| 1822 } | 1790 } |
| 1823 | 1791 |
| 1824 // Confirm that searching through the history works properly | 1792 // Confirm that searching through the history works properly |
| 1825 IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) { | 1793 IN_PROC_BROWSER_TEST_F(DownloadTest, SearchDownloads) { |
| 1826 // Downloads to populate history with. | |
| 1827 base::Time current(base::Time::Now()); | |
| 1828 DownloadPersistentStoreInfo population_entries[] = { | |
| 1829 DownloadPersistentStoreInfo( | |
| 1830 FilePath(FILE_PATH_LITERAL("/path/to/file")), | |
| 1831 GURL("http://www.google.com/fantasy_download"), | |
| 1832 GURL(""), | |
| 1833 current - base::TimeDelta::FromMinutes(5), | |
| 1834 current, | |
| 1835 128, | |
| 1836 128, | |
| 1837 DownloadItem::COMPLETE, | |
| 1838 1, | |
| 1839 false), | |
| 1840 DownloadPersistentStoreInfo( | |
| 1841 FilePath(FILE_PATH_LITERAL("/path/to/another_file")), | |
| 1842 GURL("http://www.google.com/reality_download"), | |
| 1843 GURL(""), | |
| 1844 current - base::TimeDelta::FromMinutes(10), | |
| 1845 current, | |
| 1846 256, | |
| 1847 256, | |
| 1848 DownloadItem::COMPLETE, | |
| 1849 2, | |
| 1850 false), | |
| 1851 DownloadPersistentStoreInfo( | |
| 1852 FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")), | |
| 1853 GURL("http://www.izzle.com/not_really_a_download"), | |
| 1854 GURL(""), | |
| 1855 current - base::TimeDelta::FromMinutes(15), | |
| 1856 current, | |
| 1857 512, | |
| 1858 512, | |
| 1859 DownloadItem::COMPLETE, | |
| 1860 3, | |
| 1861 true) | |
| 1862 }; | |
| 1863 std::vector<DownloadPersistentStoreInfo> entries( | |
| 1864 population_entries, population_entries + arraysize(population_entries)); | |
| 1865 | |
| 1866 // Populate the manager. | 1794 // Populate the manager. |
| 1867 DownloadManager* manager = DownloadManagerForBrowser(browser()); | 1795 DownloadManager* manager = DownloadManagerForBrowser(browser()); |
| 1868 manager->OnPersistentStoreQueryComplete(&entries); | 1796 base::Time current(base::Time::Now()); |
| 1797 manager->CreateDownloadItem( |
| 1798 FilePath(FILE_PATH_LITERAL("/path/to/file")), |
| 1799 GURL("http://www.google.com/fantasy_download"), |
| 1800 GURL(""), |
| 1801 current - base::TimeDelta::FromMinutes(5), |
| 1802 current, |
| 1803 128, |
| 1804 128, |
| 1805 DownloadItem::COMPLETE, |
| 1806 false); |
| 1807 manager->CreateDownloadItem( |
| 1808 FilePath(FILE_PATH_LITERAL("/path/to/another_file")), |
| 1809 GURL("http://www.google.com/reality_download"), |
| 1810 GURL(""), |
| 1811 current - base::TimeDelta::FromMinutes(10), |
| 1812 current, |
| 1813 256, |
| 1814 256, |
| 1815 DownloadItem::COMPLETE, |
| 1816 false); |
| 1817 manager->CreateDownloadItem( |
| 1818 FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")), |
| 1819 GURL("http://www.izzle.com/not_really_a_download"), |
| 1820 GURL(""), |
| 1821 current - base::TimeDelta::FromMinutes(15), |
| 1822 current, |
| 1823 512, |
| 1824 512, |
| 1825 DownloadItem::COMPLETE, |
| 1826 true); |
| 1869 | 1827 |
| 1870 // Do some searches and check the results. | 1828 // Do some searches and check the results. |
| 1871 std::vector<DownloadItem*> search_results; | 1829 std::vector<DownloadItem*> search_results; |
| 1872 | 1830 |
| 1873 manager->SearchDownloads(string16(), &search_results); | 1831 manager->SearchDownloads(string16(), &search_results); |
| 1874 ASSERT_EQ(3u, search_results.size()); | 1832 ASSERT_EQ(3u, search_results.size()); |
| 1875 std::sort(search_results.begin(), search_results.end(), | 1833 std::sort(search_results.begin(), search_results.end(), |
| 1876 DownloadItemSorter); | 1834 DownloadItemSorter); |
| 1877 // We do a full check only once to protect against the data | 1835 // We do a full check only once to protect against the data |
| 1878 // somehow getting scrambled on its way into the DownloadItems. | 1836 // somehow getting scrambled on its way into the DownloadItems. |
| 1879 { | 1837 { |
| 1880 DownloadItem* d1 = search_results[0]; | 1838 DownloadItem* d1 = search_results[0]; |
| 1881 DownloadItem* d2 = search_results[1]; | 1839 DownloadItem* d2 = search_results[1]; |
| 1882 DownloadItem* d3 = search_results[2]; | 1840 DownloadItem* d3 = search_results[2]; |
| 1883 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/file")), d1->GetFullPath()); | 1841 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/file")), d1->GetFullPath()); |
| 1884 EXPECT_EQ(GURL("http://www.google.com/fantasy_download"), | 1842 EXPECT_EQ(GURL("http://www.google.com/fantasy_download"), |
| 1885 d1->GetOriginalUrl()); | 1843 d1->GetOriginalUrl()); |
| 1886 EXPECT_EQ(current - base::TimeDelta::FromMinutes(5), | 1844 EXPECT_EQ(current - base::TimeDelta::FromMinutes(5), |
| 1887 d1->GetStartTime()); | 1845 d1->GetStartTime()); |
| 1888 EXPECT_EQ(current, d1->GetEndTime()); | 1846 EXPECT_EQ(current, d1->GetEndTime()); |
| 1889 EXPECT_EQ(128, d1->GetReceivedBytes()); | 1847 EXPECT_EQ(128, d1->GetReceivedBytes()); |
| 1890 EXPECT_EQ(128, d1->GetTotalBytes()); | 1848 EXPECT_EQ(128, d1->GetTotalBytes()); |
| 1891 EXPECT_EQ(DownloadItem::COMPLETE, d1->GetState()); | 1849 EXPECT_EQ(DownloadItem::COMPLETE, d1->GetState()); |
| 1892 EXPECT_EQ(1, d1->GetDbHandle()); | |
| 1893 EXPECT_FALSE(d1->GetOpened()); | 1850 EXPECT_FALSE(d1->GetOpened()); |
| 1894 | 1851 |
| 1895 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/another_file")), | 1852 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/path/to/another_file")), |
| 1896 d2->GetFullPath()); | 1853 d2->GetFullPath()); |
| 1897 EXPECT_EQ(GURL("http://www.google.com/reality_download"), | 1854 EXPECT_EQ(GURL("http://www.google.com/reality_download"), |
| 1898 d2->GetOriginalUrl()); | 1855 d2->GetOriginalUrl()); |
| 1899 EXPECT_EQ(current - base::TimeDelta::FromMinutes(10), | 1856 EXPECT_EQ(current - base::TimeDelta::FromMinutes(10), |
| 1900 d2->GetStartTime()); | 1857 d2->GetStartTime()); |
| 1901 EXPECT_EQ(current, d2->GetEndTime()); | 1858 EXPECT_EQ(current, d2->GetEndTime()); |
| 1902 EXPECT_EQ(256, d2->GetReceivedBytes()); | 1859 EXPECT_EQ(256, d2->GetReceivedBytes()); |
| 1903 EXPECT_EQ(256, d2->GetTotalBytes()); | 1860 EXPECT_EQ(256, d2->GetTotalBytes()); |
| 1904 EXPECT_EQ(DownloadItem::COMPLETE, d2->GetState()); | 1861 EXPECT_EQ(DownloadItem::COMPLETE, d2->GetState()); |
| 1905 EXPECT_EQ(2, d2->GetDbHandle()); | |
| 1906 EXPECT_FALSE(d2->GetOpened()); | 1862 EXPECT_FALSE(d2->GetOpened()); |
| 1907 | 1863 |
| 1908 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")), | 1864 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("/different_path/to/another_file")), |
| 1909 d3->GetFullPath()); | 1865 d3->GetFullPath()); |
| 1910 EXPECT_EQ(GURL("http://www.izzle.com/not_really_a_download"), | 1866 EXPECT_EQ(GURL("http://www.izzle.com/not_really_a_download"), |
| 1911 d3->GetOriginalUrl()); | 1867 d3->GetOriginalUrl()); |
| 1912 EXPECT_EQ(current - base::TimeDelta::FromMinutes(15), | 1868 EXPECT_EQ(current - base::TimeDelta::FromMinutes(15), |
| 1913 d3->GetStartTime()); | 1869 d3->GetStartTime()); |
| 1914 EXPECT_EQ(current, d3->GetEndTime()); | 1870 EXPECT_EQ(current, d3->GetEndTime()); |
| 1915 EXPECT_EQ(512, d3->GetReceivedBytes()); | 1871 EXPECT_EQ(512, d3->GetReceivedBytes()); |
| 1916 EXPECT_EQ(512, d3->GetTotalBytes()); | 1872 EXPECT_EQ(512, d3->GetTotalBytes()); |
| 1917 EXPECT_EQ(DownloadItem::COMPLETE, d3->GetState()); | 1873 EXPECT_EQ(DownloadItem::COMPLETE, d3->GetState()); |
| 1918 EXPECT_EQ(3, d3->GetDbHandle()); | |
| 1919 EXPECT_TRUE(d3->GetOpened()); | 1874 EXPECT_TRUE(d3->GetOpened()); |
| 1920 } | 1875 } |
| 1921 search_results.clear(); | 1876 search_results.clear(); |
| 1922 | 1877 |
| 1923 string16 search_input; | 1878 string16 search_input; |
| 1924 manager->SearchDownloads(UTF8ToUTF16("www.google.com"), &search_results); | 1879 manager->SearchDownloads(UTF8ToUTF16("www.google.com"), &search_results); |
| 1925 ASSERT_EQ(2u, search_results.size()); | 1880 ASSERT_EQ(2u, search_results.size()); |
| 1926 std::sort(search_results.begin(), search_results.end(), | 1881 std::sort(search_results.begin(), search_results.end(), |
| 1927 DownloadItemSorter); | 1882 DownloadItemSorter); |
| 1928 EXPECT_EQ(1, search_results[0]->GetDbHandle()); | |
| 1929 EXPECT_EQ(2, search_results[1]->GetDbHandle()); | |
| 1930 search_results.clear(); | 1883 search_results.clear(); |
| 1931 | 1884 |
| 1932 manager->SearchDownloads(UTF8ToUTF16("real"), &search_results); | 1885 manager->SearchDownloads(UTF8ToUTF16("real"), &search_results); |
| 1933 ASSERT_EQ(2u, search_results.size()); | 1886 ASSERT_EQ(2u, search_results.size()); |
| 1934 std::sort(search_results.begin(), search_results.end(), | 1887 std::sort(search_results.begin(), search_results.end(), |
| 1935 DownloadItemSorter); | 1888 DownloadItemSorter); |
| 1936 EXPECT_EQ(2, search_results[0]->GetDbHandle()); | |
| 1937 EXPECT_EQ(3, search_results[1]->GetDbHandle()); | |
| 1938 search_results.clear(); | 1889 search_results.clear(); |
| 1939 | 1890 |
| 1940 manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results); | 1891 manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results); |
| 1941 ASSERT_EQ(2u, search_results.size()); | 1892 ASSERT_EQ(2u, search_results.size()); |
| 1942 std::sort(search_results.begin(), search_results.end(), | 1893 std::sort(search_results.begin(), search_results.end(), |
| 1943 DownloadItemSorter); | 1894 DownloadItemSorter); |
| 1944 EXPECT_EQ(2, search_results[0]->GetDbHandle()); | |
| 1945 EXPECT_EQ(3, search_results[1]->GetDbHandle()); | |
| 1946 search_results.clear(); | 1895 search_results.clear(); |
| 1947 } | 1896 } |
| 1948 | 1897 |
| 1949 // Tests for download initiation functions. | 1898 // Tests for download initiation functions. |
| 1950 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { | 1899 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { |
| 1951 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1900 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1952 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1901 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1953 | 1902 |
| 1954 // DownloadUrl always prompts; return acceptance of whatever it prompts. | 1903 // DownloadUrl always prompts; return acceptance of whatever it prompts. |
| 1955 EnableFileChooser(true); | 1904 EnableFileChooser(true); |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2469 GetDownloads(browser(), &download_items); | 2418 GetDownloads(browser(), &download_items); |
| 2470 ASSERT_EQ(1u, download_items.size()); | 2419 ASSERT_EQ(1u, download_items.size()); |
| 2471 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), | 2420 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), |
| 2472 download_items[0]->GetOriginalUrl()); | 2421 download_items[0]->GetOriginalUrl()); |
| 2473 | 2422 |
| 2474 // Check that the file contains the expected referrer. | 2423 // Check that the file contains the expected referrer. |
| 2475 FilePath file(download_items[0]->GetFullPath()); | 2424 FilePath file(download_items[0]->GetFullPath()); |
| 2476 std::string expected_contents = test_server()->GetURL("").spec(); | 2425 std::string expected_contents = test_server()->GetURL("").spec(); |
| 2477 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); | 2426 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); |
| 2478 } | 2427 } |
| OLD | NEW |