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 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 ExpectWindowCountAfterDownload(1); | 1351 ExpectWindowCountAfterDownload(1); |
1405 #endif | 1352 #endif |
1406 | 1353 |
1407 EXPECT_EQ(1, browser()->tab_count()); | 1354 EXPECT_EQ(1, browser()->tab_count()); |
1408 // Download shelf should close. Download panel stays open on ChromeOS. | 1355 // Download shelf should close. Download panel stays open on ChromeOS. |
1409 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1356 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1410 | 1357 |
1411 CheckDownload(browser(), file, file); | 1358 CheckDownload(browser(), file, file); |
1412 } | 1359 } |
1413 | 1360 |
1414 // Confirm a download makes it into the history properly. | |
1415 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { | |
1416 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
1417 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
1418 FilePath origin_file(OriginFile(file)); | |
1419 int64 origin_size; | |
1420 file_util::GetFileSize(origin_file, &origin_size); | |
1421 | |
1422 // Download the file and wait. We do not expect the Select File dialog. | |
1423 DownloadAndWait(browser(), url); | |
1424 | |
1425 // Get details of what downloads have just happened. | |
1426 std::vector<DownloadItem*> downloads; | |
1427 GetDownloads(browser(), &downloads); | |
1428 ASSERT_EQ(1u, downloads.size()); | |
1429 int64 db_handle = downloads[0]->GetDbHandle(); | |
1430 | |
1431 // Check state. | |
1432 EXPECT_EQ(1, browser()->tab_count()); | |
1433 CheckDownload(browser(), file, file); | |
1434 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | |
1435 | |
1436 // Check history results. | |
1437 DownloadsHistoryDataCollector history_collector( | |
1438 db_handle, | |
1439 DownloadManagerForBrowser(browser())); | |
1440 DownloadPersistentStoreInfo info; | |
1441 EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle; | |
1442 EXPECT_EQ(file, info.path.BaseName()); | |
1443 EXPECT_EQ(url, info.url); | |
1444 // Ignore start_time. | |
1445 EXPECT_EQ(origin_size, info.received_bytes); | |
1446 EXPECT_EQ(origin_size, info.total_bytes); | |
1447 EXPECT_EQ(DownloadItem::COMPLETE, info.state); | |
1448 } | |
1449 | |
1450 // Test for crbug.com/14505. This tests that chrome:// urls are still functional | 1361 // Test for crbug.com/14505. This tests that chrome:// urls are still functional |
1451 // after download of a file while viewing another chrome://. | 1362 // after download of a file while viewing another chrome://. |
1452 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { | 1363 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { |
1453 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1364 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1454 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1365 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1455 GURL flags_url(chrome::kChromeUIFlagsURL); | 1366 GURL flags_url(chrome::kChromeUIFlagsURL); |
1456 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); | 1367 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); |
1457 | 1368 |
1458 ui_test_utils::NavigateToURL(browser(), flags_url); | 1369 ui_test_utils::NavigateToURL(browser(), flags_url); |
1459 DownloadAndWait(browser(), download_url); | 1370 DownloadAndWait(browser(), download_url); |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2235 GetDownloads(browser(), &download_items); | 2146 GetDownloads(browser(), &download_items); |
2236 ASSERT_EQ(1u, download_items.size()); | 2147 ASSERT_EQ(1u, download_items.size()); |
2237 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), | 2148 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), |
2238 download_items[0]->GetOriginalUrl()); | 2149 download_items[0]->GetOriginalUrl()); |
2239 | 2150 |
2240 // Check that the file contains the expected referrer. | 2151 // Check that the file contains the expected referrer. |
2241 FilePath file(download_items[0]->GetFullPath()); | 2152 FilePath file(download_items[0]->GetFullPath()); |
2242 std::string expected_contents = test_server()->GetURL("").spec(); | 2153 std::string expected_contents = test_server()->GetURL("").spec(); |
2243 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); | 2154 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); |
2244 } | 2155 } |
OLD | NEW |