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 // Disable everything on windows only. http://crbug.com/306144 | 5 // Disable everything on windows only. http://crbug.com/306144 |
6 #ifndef OS_WIN | 6 #ifndef OS_WIN |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "chrome/browser/download/download_service_factory.h" | 24 #include "chrome/browser/download/download_service_factory.h" |
25 #include "chrome/browser/download/download_test_file_activity_observer.h" | 25 #include "chrome/browser/download/download_test_file_activity_observer.h" |
26 #include "chrome/browser/extensions/api/downloads/downloads_api.h" | 26 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
27 #include "chrome/browser/extensions/browser_action_test_util.h" | 27 #include "chrome/browser/extensions/browser_action_test_util.h" |
28 #include "chrome/browser/extensions/extension_apitest.h" | 28 #include "chrome/browser/extensions/extension_apitest.h" |
29 #include "chrome/browser/extensions/extension_function_test_utils.h" | 29 #include "chrome/browser/extensions/extension_function_test_utils.h" |
30 #include "chrome/browser/net/url_request_mock_util.h" | 30 #include "chrome/browser/net/url_request_mock_util.h" |
31 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
32 #include "chrome/browser/ui/browser.h" | 32 #include "chrome/browser/ui/browser.h" |
33 #include "chrome/browser/ui/browser_tabstrip.h" | 33 #include "chrome/browser/ui/browser_tabstrip.h" |
| 34 #include "chrome/common/extensions/api/downloads.h" |
34 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
35 #include "chrome/test/base/in_process_browser_test.h" | 36 #include "chrome/test/base/in_process_browser_test.h" |
36 #include "chrome/test/base/ui_test_utils.h" | 37 #include "chrome/test/base/ui_test_utils.h" |
37 #include "components/prefs/pref_service.h" | 38 #include "components/prefs/pref_service.h" |
38 #include "content/public/browser/browser_context.h" | 39 #include "content/public/browser/browser_context.h" |
39 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
40 #include "content/public/browser/download_item.h" | 41 #include "content/public/browser/download_item.h" |
41 #include "content/public/browser/download_manager.h" | 42 #include "content/public/browser/download_manager.h" |
42 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
43 #include "content/public/browser/storage_partition.h" | 44 #include "content/public/browser/storage_partition.h" |
(...skipping 1724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1768 }; | 1769 }; |
1769 | 1770 |
1770 for (size_t index = 0; index < arraysize(kInvalidURLs); ++index) { | 1771 for (size_t index = 0; index < arraysize(kInvalidURLs); ++index) { |
1771 EXPECT_STREQ(errors::kInvalidURL, | 1772 EXPECT_STREQ(errors::kInvalidURL, |
1772 RunFunctionAndReturnError(new DownloadsDownloadFunction(), | 1773 RunFunctionAndReturnError(new DownloadsDownloadFunction(), |
1773 base::StringPrintf( | 1774 base::StringPrintf( |
1774 "[{\"url\": \"%s\"}]", kInvalidURLs[index])).c_str()) | 1775 "[{\"url\": \"%s\"}]", kInvalidURLs[index])).c_str()) |
1775 << kInvalidURLs[index]; | 1776 << kInvalidURLs[index]; |
1776 } | 1777 } |
1777 | 1778 |
1778 EXPECT_STREQ("NETWORK_INVALID_REQUEST", RunFunctionAndReturnError( | 1779 int result_id = -1; |
| 1780 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
1779 new DownloadsDownloadFunction(), | 1781 new DownloadsDownloadFunction(), |
1780 "[{\"url\": \"javascript:document.write(\\\"hello\\\");\"}]").c_str()); | 1782 "[{\"url\": \"javascript:document.write(\\\"hello\\\");\"}]")); |
1781 EXPECT_STREQ("NETWORK_INVALID_REQUEST", RunFunctionAndReturnError( | 1783 ASSERT_TRUE(result.get()); |
| 1784 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1785 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1786 ASSERT_TRUE(item); |
| 1787 ASSERT_TRUE( |
| 1788 WaitFor(downloads::OnCreated::kEventName, |
| 1789 "[{\"error\": \"NETWORK_INVALID_REQUEST\"," |
| 1790 " \"state\": \"interrupted\"," |
| 1791 " \"url\": \"javascript:document.write(\\\"hello\\\");\"}]")); |
| 1792 |
| 1793 result.reset( |
| 1794 RunFunctionAndReturnResult(new DownloadsDownloadFunction(), |
| 1795 "[{\"url\": \"javascript:return false;\"}]")); |
| 1796 ASSERT_TRUE(result.get()); |
| 1797 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1798 item = GetCurrentManager()->GetDownload(result_id); |
| 1799 ASSERT_TRUE(item); |
| 1800 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
| 1801 "[{\"error\": \"NETWORK_INVALID_REQUEST\"," |
| 1802 " \"state\": \"interrupted\"," |
| 1803 " \"url\": \"javascript:return false;\"}]")); |
| 1804 |
| 1805 result.reset(RunFunctionAndReturnResult( |
1782 new DownloadsDownloadFunction(), | 1806 new DownloadsDownloadFunction(), |
1783 "[{\"url\": \"javascript:return false;\"}]").c_str()); | 1807 "[{\"url\": \"ftp://example.com/example.txt\"}]")); |
1784 EXPECT_STREQ("NETWORK_FAILED", RunFunctionAndReturnError( | 1808 ASSERT_TRUE(result.get()); |
1785 new DownloadsDownloadFunction(), | 1809 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
1786 "[{\"url\": \"ftp://example.com/example.txt\"}]").c_str()); | 1810 item = GetCurrentManager()->GetDownload(result_id); |
| 1811 ASSERT_TRUE(item); |
| 1812 ASSERT_TRUE(WaitFor(downloads::OnCreated::kEventName, |
| 1813 "[{\"error\": \"NETWORK_FAILED\"," |
| 1814 " \"state\": \"interrupted\"," |
| 1815 " \"url\": \"ftp://example.com/example.txt\"}]")); |
1787 } | 1816 } |
1788 | 1817 |
1789 // TODO(benjhayden): Set up a test ftp server, add ftp://localhost* to | 1818 // TODO(benjhayden): Set up a test ftp server, add ftp://localhost* to |
1790 // permissions, test downloading from ftp. | 1819 // permissions, test downloading from ftp. |
1791 | 1820 |
1792 // Valid URLs plus fragments are still valid URLs. | 1821 // Valid URLs plus fragments are still valid URLs. |
1793 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1822 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1794 DownloadExtensionTest_Download_URLFragment) { | 1823 DownloadExtensionTest_Download_URLFragment) { |
1795 LoadExtension("downloads_split"); | 1824 LoadExtension("downloads_split"); |
1796 ASSERT_TRUE(StartEmbeddedTestServer()); | 1825 ASSERT_TRUE(StartEmbeddedTestServer()); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2029 "[{\"url\": \"%s\"," | 2058 "[{\"url\": \"%s\"," |
2030 " \"filename\": \"auth-basic-fail.txt\"}]", | 2059 " \"filename\": \"auth-basic-fail.txt\"}]", |
2031 download_url.c_str()))); | 2060 download_url.c_str()))); |
2032 ASSERT_TRUE(result.get()); | 2061 ASSERT_TRUE(result.get()); |
2033 int result_id = -1; | 2062 int result_id = -1; |
2034 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2063 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2035 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2064 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2036 ASSERT_TRUE(item); | 2065 ASSERT_TRUE(item); |
2037 ScopedCancellingItem canceller(item); | 2066 ScopedCancellingItem canceller(item); |
2038 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2067 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2039 | 2068 ASSERT_TRUE( |
2040 ASSERT_TRUE(WaitForInterruption( | 2069 WaitFor(downloads::OnCreated::kEventName, |
2041 item, | 2070 base::StringPrintf("[{\"url\": \"%s\"," |
2042 content::DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED, | 2071 " \"state\": \"interrupted\"," |
2043 base::StringPrintf("[{\"danger\": \"safe\"," | 2072 " \"error\": \"SERVER_UNAUTHORIZED\"}]", |
2044 " \"incognito\": false," | 2073 download_url.c_str()))); |
2045 " \"mime\": \"text/html\"," | |
2046 " \"paused\": false," | |
2047 " \"url\": \"%s\"}]", | |
2048 download_url.c_str()))); | |
2049 } | 2074 } |
2050 | 2075 |
2051 // Test that DownloadsDownloadFunction propagates |headers| to the URLRequest. | 2076 // Test that DownloadsDownloadFunction propagates |headers| to the URLRequest. |
2052 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2077 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
2053 DownloadExtensionTest_Download_Headers) { | 2078 DownloadExtensionTest_Download_Headers) { |
2054 LoadExtension("downloads_split"); | 2079 LoadExtension("downloads_split"); |
2055 ASSERT_TRUE(StartEmbeddedTestServer()); | 2080 ASSERT_TRUE(StartEmbeddedTestServer()); |
2056 std::string download_url = | 2081 std::string download_url = |
2057 embedded_test_server() | 2082 embedded_test_server() |
2058 ->GetURL( | 2083 ->GetURL( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2123 "[{\"url\": \"%s\"," | 2148 "[{\"url\": \"%s\"," |
2124 " \"filename\": \"headers-fail.txt\"}]", | 2149 " \"filename\": \"headers-fail.txt\"}]", |
2125 download_url.c_str()))); | 2150 download_url.c_str()))); |
2126 ASSERT_TRUE(result.get()); | 2151 ASSERT_TRUE(result.get()); |
2127 int result_id = -1; | 2152 int result_id = -1; |
2128 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2153 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2129 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2154 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2130 ASSERT_TRUE(item); | 2155 ASSERT_TRUE(item); |
2131 ScopedCancellingItem canceller(item); | 2156 ScopedCancellingItem canceller(item); |
2132 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2157 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2133 | 2158 ASSERT_TRUE( |
2134 ASSERT_TRUE(WaitForInterruption( | 2159 WaitFor(downloads::OnCreated::kEventName, |
2135 item, | 2160 base::StringPrintf("[{\"url\": \"%s\"," |
2136 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, | 2161 " \"state\": \"interrupted\"," |
2137 base::StringPrintf("[{\"danger\": \"safe\"," | 2162 " \"error\": \"SERVER_BAD_CONTENT\"}]", |
2138 " \"incognito\": false," | 2163 download_url.c_str()))); |
2139 " \"bytesReceived\": 0.0," | |
2140 " \"fileSize\": 0.0," | |
2141 " \"mime\": \"\"," | |
2142 " \"paused\": false," | |
2143 " \"url\": \"%s\"}]", | |
2144 download_url.c_str()))); | |
2145 } | 2164 } |
2146 | 2165 |
2147 // Test that DownloadsDownloadFunction propagates the Authorization header | 2166 // Test that DownloadsDownloadFunction propagates the Authorization header |
2148 // correctly. | 2167 // correctly. |
2149 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2168 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
2150 DownloadExtensionTest_Download_AuthBasic) { | 2169 DownloadExtensionTest_Download_AuthBasic) { |
2151 LoadExtension("downloads_split"); | 2170 LoadExtension("downloads_split"); |
2152 ASSERT_TRUE(StartEmbeddedTestServer()); | 2171 ASSERT_TRUE(StartEmbeddedTestServer()); |
2153 std::string download_url = | 2172 std::string download_url = |
2154 embedded_test_server()->GetURL("/auth-basic").spec(); | 2173 embedded_test_server()->GetURL("/auth-basic").spec(); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2265 " \"body\": \"BODY\"," | 2284 " \"body\": \"BODY\"," |
2266 " \"filename\": \"post-get.txt\"}]", | 2285 " \"filename\": \"post-get.txt\"}]", |
2267 download_url.c_str()))); | 2286 download_url.c_str()))); |
2268 ASSERT_TRUE(result.get()); | 2287 ASSERT_TRUE(result.get()); |
2269 int result_id = -1; | 2288 int result_id = -1; |
2270 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2289 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2271 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2290 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2272 ASSERT_TRUE(item); | 2291 ASSERT_TRUE(item); |
2273 ScopedCancellingItem canceller(item); | 2292 ScopedCancellingItem canceller(item); |
2274 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2293 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2275 | 2294 ASSERT_TRUE( |
2276 ASSERT_TRUE(WaitForInterruption( | 2295 WaitFor(downloads::OnCreated::kEventName, |
2277 item, | 2296 base::StringPrintf("[{\"url\": \"%s\"," |
2278 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, | 2297 " \"state\": \"interrupted\"," |
2279 base::StringPrintf("[{\"danger\": \"safe\"," | 2298 " \"error\": \"SERVER_BAD_CONTENT\"}]", |
2280 " \"incognito\": false," | 2299 download_url.c_str()))); |
2281 " \"mime\": \"\"," | |
2282 " \"paused\": false," | |
2283 " \"id\": %d," | |
2284 " \"url\": \"%s\"}]", | |
2285 result_id, | |
2286 download_url.c_str()))); | |
2287 } | 2300 } |
2288 | 2301 |
2289 // Test that downloadPostSuccess would fail if the resource requires the POST | 2302 // Test that downloadPostSuccess would fail if the resource requires the POST |
2290 // method, and chrome fails to propagate the |body| parameter back to the | 2303 // method, and chrome fails to propagate the |body| parameter back to the |
2291 // server. This tests both that testserver.py does not succeed when it should | 2304 // server. This tests both that testserver.py does not succeed when it should |
2292 // fail, and this tests how the downloads extension api exposes the failure to | 2305 // fail, and this tests how the downloads extension api exposes the failure to |
2293 // extensions. | 2306 // extensions. |
2294 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2307 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
2295 DownloadExtensionTest_Download_Post_NoBody) { | 2308 DownloadExtensionTest_Download_Post_NoBody) { |
2296 LoadExtension("downloads_split"); | 2309 LoadExtension("downloads_split"); |
(...skipping 11 matching lines...) Expand all Loading... |
2308 " \"method\": \"POST\"," | 2321 " \"method\": \"POST\"," |
2309 " \"filename\": \"post-nobody.txt\"}]", | 2322 " \"filename\": \"post-nobody.txt\"}]", |
2310 download_url.c_str()))); | 2323 download_url.c_str()))); |
2311 ASSERT_TRUE(result.get()); | 2324 ASSERT_TRUE(result.get()); |
2312 int result_id = -1; | 2325 int result_id = -1; |
2313 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 2326 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
2314 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 2327 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
2315 ASSERT_TRUE(item); | 2328 ASSERT_TRUE(item); |
2316 ScopedCancellingItem canceller(item); | 2329 ScopedCancellingItem canceller(item); |
2317 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 2330 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
2318 | 2331 ASSERT_TRUE( |
2319 ASSERT_TRUE(WaitForInterruption( | 2332 WaitFor(downloads::OnCreated::kEventName, |
2320 item, | 2333 base::StringPrintf("[{\"url\": \"%s\"," |
2321 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, | 2334 " \"state\": \"interrupted\"," |
2322 base::StringPrintf("[{\"danger\": \"safe\"," | 2335 " \"error\": \"SERVER_BAD_CONTENT\"}]", |
2323 " \"incognito\": false," | 2336 download_url.c_str()))); |
2324 " \"mime\": \"\"," | |
2325 " \"paused\": false," | |
2326 " \"id\": %d," | |
2327 " \"url\": \"%s\"}]", | |
2328 result_id, | |
2329 download_url.c_str()))); | |
2330 } | 2337 } |
2331 | 2338 |
2332 // Test that cancel()ing an in-progress download causes its state to transition | 2339 // Test that cancel()ing an in-progress download causes its state to transition |
2333 // to interrupted, and test that that state transition is detectable by an | 2340 // to interrupted, and test that that state transition is detectable by an |
2334 // onChanged event listener. TODO(benjhayden): Test other sources of | 2341 // onChanged event listener. TODO(benjhayden): Test other sources of |
2335 // interruptions such as server death. | 2342 // interruptions such as server death. |
2336 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 2343 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
2337 DownloadExtensionTest_Download_Cancel) { | 2344 DownloadExtensionTest_Download_Cancel) { |
2338 LoadExtension("downloads_split"); | 2345 LoadExtension("downloads_split"); |
2339 ASSERT_TRUE(StartEmbeddedTestServer()); | 2346 ASSERT_TRUE(StartEmbeddedTestServer()); |
(...skipping 1820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4160 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); | 4167 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); |
4161 EXPECT_FALSE(warnings.empty()); | 4168 EXPECT_FALSE(warnings.empty()); |
4162 EXPECT_EQ(Warning::kDownloadFilenameConflict, | 4169 EXPECT_EQ(Warning::kDownloadFilenameConflict, |
4163 warnings.begin()->warning_type()); | 4170 warnings.begin()->warning_type()); |
4164 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); | 4171 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); |
4165 } | 4172 } |
4166 | 4173 |
4167 } // namespace extensions | 4174 } // namespace extensions |
4168 | 4175 |
4169 #endif // http://crbug.com/306144 | 4176 #endif // http://crbug.com/306144 |
OLD | NEW |