| 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 <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 NOTREACHED(); | 198 NOTREACHED(); |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 | 201 |
| 202 bool WaitFor(Profile* profile, | 202 bool WaitFor(Profile* profile, |
| 203 const std::string& event_name, | 203 const std::string& event_name, |
| 204 const std::string& json_args) { | 204 const std::string& json_args) { |
| 205 waiting_for_.reset(new Event(profile, event_name, json_args, base::Time())); | 205 waiting_for_.reset(new Event(profile, event_name, json_args, base::Time())); |
| 206 for (std::deque<Event*>::const_iterator iter = events_.begin(); | 206 for (std::deque<Event*>::const_iterator iter = events_.begin(); |
| 207 iter != events_.end(); ++iter) { | 207 iter != events_.end(); ++iter) { |
| 208 if ((*iter)->Satisfies(*waiting_for_.get())) { | 208 if ((*iter)->Satisfies(*waiting_for_.get())) |
| 209 return true; | 209 return true; |
| 210 } | |
| 211 } | 210 } |
| 212 waiting_ = true; | 211 waiting_ = true; |
| 213 content::RunMessageLoop(); | 212 content::RunMessageLoop(); |
| 214 bool success = !waiting_; | 213 bool success = !waiting_; |
| 215 if (waiting_) { | 214 if (waiting_) { |
| 216 // Print the events that were caught since the last WaitFor() call to help | 215 // Print the events that were caught since the last WaitFor() call to help |
| 217 // find the erroneous event. | 216 // find the erroneous event. |
| 218 // TODO(benjhayden) Fuzzy-match and highlight the erroneous event. | 217 // TODO(benjhayden) Fuzzy-match and highlight the erroneous event. |
| 219 for (std::deque<Event*>::const_iterator iter = events_.begin(); | 218 for (std::deque<Event*>::const_iterator iter = events_.begin(); |
| 220 iter != events_.end(); ++iter) { | 219 iter != events_.end(); ++iter) { |
| (...skipping 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1679 "[{\"url\": \"%s\"}]", kInvalidURLs[index])).c_str()) | 1678 "[{\"url\": \"%s\"}]", kInvalidURLs[index])).c_str()) |
| 1680 << kInvalidURLs[index]; | 1679 << kInvalidURLs[index]; |
| 1681 } | 1680 } |
| 1682 | 1681 |
| 1683 EXPECT_STREQ("NETWORK_INVALID_REQUEST", RunFunctionAndReturnError( | 1682 EXPECT_STREQ("NETWORK_INVALID_REQUEST", RunFunctionAndReturnError( |
| 1684 new DownloadsDownloadFunction(), | 1683 new DownloadsDownloadFunction(), |
| 1685 "[{\"url\": \"javascript:document.write(\\\"hello\\\");\"}]").c_str()); | 1684 "[{\"url\": \"javascript:document.write(\\\"hello\\\");\"}]").c_str()); |
| 1686 EXPECT_STREQ("NETWORK_INVALID_REQUEST", RunFunctionAndReturnError( | 1685 EXPECT_STREQ("NETWORK_INVALID_REQUEST", RunFunctionAndReturnError( |
| 1687 new DownloadsDownloadFunction(), | 1686 new DownloadsDownloadFunction(), |
| 1688 "[{\"url\": \"javascript:return false;\"}]").c_str()); | 1687 "[{\"url\": \"javascript:return false;\"}]").c_str()); |
| 1689 EXPECT_STREQ("NETWORK_FAILED", RunFunctionAndReturnError( | 1688 |
| 1690 new DownloadsDownloadFunction(), | 1689 std::string url_parameter = "[{\"url\": \"ftp://example.com/example.txt\"}]"; |
| 1691 "[{\"url\": \"ftp://example.com/example.txt\"}]").c_str()); | 1690 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1691 new DownloadsDownloadFunction(), url_parameter)); |
| 1692 ASSERT_TRUE(result.get()); |
| 1693 int result_id = -1; |
| 1694 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1695 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1696 ASSERT_TRUE(item); |
| 1697 ScopedCancellingItem canceller(item); |
| 1698 ASSERT_TRUE(WaitForInterruption( |
| 1699 item, content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, url_parameter)); |
| 1692 } | 1700 } |
| 1693 | 1701 |
| 1694 // TODO(benjhayden): Set up a test ftp server, add ftp://localhost* to | 1702 // TODO(benjhayden): Set up a test ftp server, add ftp://localhost* to |
| 1695 // permissions, test downloading from ftp. | 1703 // permissions, test downloading from ftp. |
| 1696 | 1704 |
| 1697 // Valid URLs plus fragments are still valid URLs. | 1705 // Valid URLs plus fragments are still valid URLs. |
| 1698 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1706 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 1699 DownloadExtensionTest_Download_URLFragment) { | 1707 DownloadExtensionTest_Download_URLFragment) { |
| 1700 LoadExtension("downloads_split"); | 1708 LoadExtension("downloads_split"); |
| 1701 ASSERT_TRUE(StartEmbeddedTestServer()); | 1709 ASSERT_TRUE(StartEmbeddedTestServer()); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1822 result_id, | 1830 result_id, |
| 1823 GetFilename("file.txt").c_str()))); | 1831 GetFilename("file.txt").c_str()))); |
| 1824 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, | 1832 ASSERT_TRUE(WaitFor(api::OnChanged::kEventName, |
| 1825 base::StringPrintf("[{\"id\": %d," | 1833 base::StringPrintf("[{\"id\": %d," |
| 1826 " \"state\": {" | 1834 " \"state\": {" |
| 1827 " \"previous\": \"in_progress\"," | 1835 " \"previous\": \"in_progress\"," |
| 1828 " \"current\": \"complete\"}}]", | 1836 " \"current\": \"complete\"}}]", |
| 1829 result_id))); | 1837 result_id))); |
| 1830 } | 1838 } |
| 1831 | 1839 |
| 1832 // Test that auth-basic-succeed would fail if the resource requires the | 1840 // Test that auth-basic would fail if the resource requires the Authorization |
| 1833 // Authorization header and chrome fails to propagate it back to the server. | 1841 // header and chrome fails to propagate it back to the server. This tests both |
| 1834 // This tests both that testserver.py does not succeed when it should fail as | 1842 // that the embedded test server does not succeed when it should fail as well as |
| 1835 // well as how the downloads extension API exposes the failure to extensions. | 1843 // how the downloads extension API exposes the failure to extensions. |
| 1836 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1844 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 1837 DownloadExtensionTest_Download_AuthBasic_Fail) { | 1845 DownloadExtensionTest_Download_AuthBasic_Fail) { |
| 1838 LoadExtension("downloads_split"); | 1846 LoadExtension("downloads_split"); |
| 1839 ASSERT_TRUE(StartEmbeddedTestServer()); | 1847 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 1840 ASSERT_TRUE(test_server()->Start()); | 1848 ASSERT_TRUE(test_server()->Start()); |
| 1841 std::string download_url = test_server()->GetURL("auth-basic").spec(); | 1849 std::string download_url = test_server()->GetURL("auth-basic").spec(); |
| 1842 GoOnTheRecord(); | 1850 GoOnTheRecord(); |
| 1843 | 1851 |
| 1844 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1852 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
| 1845 new DownloadsDownloadFunction(), base::StringPrintf( | 1853 new DownloadsDownloadFunction(), base::StringPrintf( |
| 1846 "[{\"url\": \"%s\"," | 1854 "[{\"url\": \"%s\"," |
| 1847 " \"filename\": \"auth-basic-fail.txt\"}]", | 1855 " \"filename\": \"auth-basic-fail.txt\"}]", |
| 1848 download_url.c_str()))); | 1856 download_url.c_str()))); |
| 1849 ASSERT_TRUE(result.get()); | 1857 ASSERT_TRUE(result.get()); |
| 1850 int result_id = -1; | 1858 int result_id = -1; |
| 1851 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1859 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1852 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 1860 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1853 ASSERT_TRUE(item); | 1861 ASSERT_TRUE(item); |
| 1854 ScopedCancellingItem canceller(item); | 1862 ScopedCancellingItem canceller(item); |
| 1855 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1863 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1856 | 1864 ASSERT_TRUE( |
| 1857 ASSERT_TRUE(WaitForInterruption( | 1865 WaitForInterruption(item, |
| 1858 item, | 1866 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, |
| 1859 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, | 1867 base::StringPrintf( |
| 1860 base::StringPrintf("[{\"danger\": \"safe\"," | 1868 "[{\"danger\": \"safe\"," |
| 1861 " \"incognito\": false," | 1869 " \"incognito\": false," |
| 1862 " \"mime\": \"text/html\"," | 1870 " \"mime\": \"\"," |
| 1863 " \"paused\": false," | 1871 " \"paused\": false," |
| 1864 " \"url\": \"%s\"}]", | 1872 " \"url\": \"%s\"}]", |
| 1865 download_url.c_str()))); | 1873 download_url.c_str()))); |
| 1866 } | 1874 } |
| 1867 | 1875 |
| 1868 // Test that DownloadsDownloadFunction propagates |headers| to the URLRequest. | 1876 // Test that DownloadsDownloadFunction propagates |headers| to the URLRequest. |
| 1869 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1877 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 1870 DownloadExtensionTest_Download_Headers) { | 1878 DownloadExtensionTest_Download_Headers) { |
| 1871 LoadExtension("downloads_split"); | 1879 LoadExtension("downloads_split"); |
| 1872 ASSERT_TRUE(StartEmbeddedTestServer()); | 1880 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 1873 ASSERT_TRUE(test_server()->Start()); | 1881 ASSERT_TRUE(test_server()->Start()); |
| 1874 std::string download_url = test_server()->GetURL("files/downloads/" | 1882 std::string download_url = test_server()->GetURL("files/downloads/" |
| 1875 "a_zip_file.zip?expected_headers=Foo:bar&expected_headers=Qx:yo").spec(); | 1883 "a_zip_file.zip?expected_headers=Foo:bar&expected_headers=Qx:yo").spec(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1932 " \"filename\": \"headers-fail.txt\"}]", | 1940 " \"filename\": \"headers-fail.txt\"}]", |
| 1933 download_url.c_str()))); | 1941 download_url.c_str()))); |
| 1934 ASSERT_TRUE(result.get()); | 1942 ASSERT_TRUE(result.get()); |
| 1935 int result_id = -1; | 1943 int result_id = -1; |
| 1936 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1944 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
| 1937 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | 1945 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); |
| 1938 ASSERT_TRUE(item); | 1946 ASSERT_TRUE(item); |
| 1939 ScopedCancellingItem canceller(item); | 1947 ScopedCancellingItem canceller(item); |
| 1940 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | 1948 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); |
| 1941 | 1949 |
| 1942 ASSERT_TRUE(WaitForInterruption( | 1950 ASSERT_TRUE( |
| 1943 item, | 1951 WaitForInterruption(item, |
| 1944 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, | 1952 content::DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, |
| 1945 base::StringPrintf("[{\"danger\": \"safe\"," | 1953 base::StringPrintf( |
| 1946 " \"incognito\": false," | 1954 "[{\"danger\": \"safe\"," |
| 1947 " \"bytesReceived\": 0.0," | 1955 " \"incognito\": false," |
| 1948 " \"fileSize\": 0.0," | 1956 " \"bytesReceived\": 0.0," |
| 1949 " \"mime\": \"\"," | 1957 " \"fileSize\": -1.0," |
| 1950 " \"paused\": false," | 1958 " \"mime\": \"\"," |
| 1951 " \"url\": \"%s\"}]", | 1959 " \"paused\": false," |
| 1952 download_url.c_str()))); | 1960 " \"url\": \"%s\"}]", |
| 1961 download_url.c_str()))); |
| 1953 } | 1962 } |
| 1954 | 1963 |
| 1955 // Test that DownloadsDownloadFunction propagates the Authorization header | 1964 // Test that DownloadsDownloadFunction propagates the Authorization header |
| 1956 // correctly. | 1965 // correctly. |
| 1957 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1966 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
| 1958 DownloadExtensionTest_Download_AuthBasic) { | 1967 DownloadExtensionTest_Download_AuthBasic) { |
| 1959 LoadExtension("downloads_split"); | 1968 LoadExtension("downloads_split"); |
| 1960 ASSERT_TRUE(StartEmbeddedTestServer()); | 1969 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 1961 ASSERT_TRUE(test_server()->Start()); | 1970 ASSERT_TRUE(test_server()->Start()); |
| 1962 std::string download_url = test_server()->GetURL("auth-basic").spec(); | 1971 std::string download_url = test_server()->GetURL("auth-basic").spec(); |
| (...skipping 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3635 EXPECT_EQ("suggester", winner_id); | 3644 EXPECT_EQ("suggester", winner_id); |
| 3636 EXPECT_EQ(FILE_PATH_LITERAL("b"), filename.value()); | 3645 EXPECT_EQ(FILE_PATH_LITERAL("b"), filename.value()); |
| 3637 EXPECT_EQ(api::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); | 3646 EXPECT_EQ(api::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); |
| 3638 EXPECT_FALSE(warnings.empty()); | 3647 EXPECT_FALSE(warnings.empty()); |
| 3639 EXPECT_EQ(extensions::ExtensionWarning::kDownloadFilenameConflict, | 3648 EXPECT_EQ(extensions::ExtensionWarning::kDownloadFilenameConflict, |
| 3640 warnings.begin()->warning_type()); | 3649 warnings.begin()->warning_type()); |
| 3641 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); | 3650 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); |
| 3642 } | 3651 } |
| 3643 | 3652 |
| 3644 #endif // http://crbug.com/3061144 | 3653 #endif // http://crbug.com/3061144 |
| OLD | NEW |