Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api_unittest.cc

Issue 16268017: GTTF: convert some tests in chrome to use EmbeddedTestServer patch nr 1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 1523 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 off_item_arg); 1534 off_item_arg);
1535 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 1535 EXPECT_STREQ(download_extension_errors::kInvalidOperationError,
1536 error.c_str()); 1536 error.c_str());
1537 } 1537 }
1538 1538
1539 // Test that we can start a download and that the correct sequence of events is 1539 // Test that we can start a download and that the correct sequence of events is
1540 // fired for it. 1540 // fired for it.
1541 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1541 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1542 DownloadExtensionTest_Download_Basic) { 1542 DownloadExtensionTest_Download_Basic) {
1543 LoadExtension("downloads_split"); 1543 LoadExtension("downloads_split");
1544 CHECK(StartTestServer()); 1544 ASSERT_TRUE(StartEmbeddedTestServer());
1545 ASSERT_TRUE(test_server()->Start());
1545 std::string download_url = test_server()->GetURL("slow?0").spec(); 1546 std::string download_url = test_server()->GetURL("slow?0").spec();
1546 GoOnTheRecord(); 1547 GoOnTheRecord();
1547 1548
1548 // Start downloading a file. 1549 // Start downloading a file.
1549 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 1550 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
1550 new DownloadsDownloadFunction(), base::StringPrintf( 1551 new DownloadsDownloadFunction(), base::StringPrintf(
1551 "[{\"url\": \"%s\"}]", download_url.c_str()))); 1552 "[{\"url\": \"%s\"}]", download_url.c_str())));
1552 ASSERT_TRUE(result.get()); 1553 ASSERT_TRUE(result.get());
1553 int result_id = -1; 1554 int result_id = -1;
1554 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1555 ASSERT_TRUE(result->GetAsInteger(&result_id));
(...skipping 22 matching lines...) Expand all
1577 " \"previous\": \"in_progress\"," 1578 " \"previous\": \"in_progress\","
1578 " \"current\": \"complete\"}}]", 1579 " \"current\": \"complete\"}}]",
1579 result_id))); 1580 result_id)));
1580 } 1581 }
1581 1582
1582 // Test that we can start a download from an incognito context, and that the 1583 // Test that we can start a download from an incognito context, and that the
1583 // download knows that it's incognito. 1584 // download knows that it's incognito.
1584 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1585 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1585 DownloadExtensionTest_Download_Incognito) { 1586 DownloadExtensionTest_Download_Incognito) {
1586 LoadExtension("downloads_split"); 1587 LoadExtension("downloads_split");
1587 CHECK(StartTestServer()); 1588 ASSERT_TRUE(StartEmbeddedTestServer());
1589 ASSERT_TRUE(test_server()->Start());
1588 GoOffTheRecord(); 1590 GoOffTheRecord();
1589 std::string download_url = test_server()->GetURL("slow?0").spec(); 1591 std::string download_url = test_server()->GetURL("slow?0").spec();
1590 1592
1591 // Start downloading a file. 1593 // Start downloading a file.
1592 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 1594 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
1593 new DownloadsDownloadFunction(), base::StringPrintf( 1595 new DownloadsDownloadFunction(), base::StringPrintf(
1594 "[{\"url\": \"%s\"}]", download_url.c_str()))); 1596 "[{\"url\": \"%s\"}]", download_url.c_str())));
1595 ASSERT_TRUE(result.get()); 1597 ASSERT_TRUE(result.get());
1596 int result_id = -1; 1598 int result_id = -1;
1597 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1599 ASSERT_TRUE(result->GetAsInteger(&result_id));
(...skipping 30 matching lines...) Expand all
1628 DISABLED_DownloadExtensionTest_Download_UnsafeHeaders 1630 DISABLED_DownloadExtensionTest_Download_UnsafeHeaders
1629 #else 1631 #else
1630 #define MAYBE_DownloadExtensionTest_Download_UnsafeHeaders \ 1632 #define MAYBE_DownloadExtensionTest_Download_UnsafeHeaders \
1631 DownloadExtensionTest_Download_UnsafeHeaders 1633 DownloadExtensionTest_Download_UnsafeHeaders
1632 #endif 1634 #endif
1633 1635
1634 // Test that we disallow certain headers case-insensitively. 1636 // Test that we disallow certain headers case-insensitively.
1635 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1637 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1636 MAYBE_DownloadExtensionTest_Download_UnsafeHeaders) { 1638 MAYBE_DownloadExtensionTest_Download_UnsafeHeaders) {
1637 LoadExtension("downloads_split"); 1639 LoadExtension("downloads_split");
1638 CHECK(StartTestServer()); 1640 ASSERT_TRUE(StartEmbeddedTestServer());
1641 ASSERT_TRUE(test_server()->Start());
1639 GoOnTheRecord(); 1642 GoOnTheRecord();
1640 1643
1641 static const char* kUnsafeHeaders[] = { 1644 static const char* kUnsafeHeaders[] = {
1642 "Accept-chArsEt", 1645 "Accept-chArsEt",
1643 "accept-eNcoding", 1646 "accept-eNcoding",
1644 "coNNection", 1647 "coNNection",
1645 "coNteNt-leNgth", 1648 "coNteNt-leNgth",
1646 "cooKIE", 1649 "cooKIE",
1647 "cOOkie2", 1650 "cOOkie2",
1648 "coNteNt-traNsfer-eNcodiNg", 1651 "coNteNt-traNsfer-eNcodiNg",
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 static_cast<int>(index), 1683 static_cast<int>(index),
1681 kUnsafeHeaders[index])).c_str()); 1684 kUnsafeHeaders[index])).c_str());
1682 } 1685 }
1683 } 1686 }
1684 1687
1685 // Test that subdirectories (slashes) are disallowed in filenames. 1688 // Test that subdirectories (slashes) are disallowed in filenames.
1686 // TODO(benjhayden) Update this when subdirectories are supported. 1689 // TODO(benjhayden) Update this when subdirectories are supported.
1687 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1690 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1688 DownloadExtensionTest_Download_Subdirectory) { 1691 DownloadExtensionTest_Download_Subdirectory) {
1689 LoadExtension("downloads_split"); 1692 LoadExtension("downloads_split");
1690 CHECK(StartTestServer()); 1693 ASSERT_TRUE(StartEmbeddedTestServer());
1694 ASSERT_TRUE(test_server()->Start());
1691 std::string download_url = test_server()->GetURL("slow?0").spec(); 1695 std::string download_url = test_server()->GetURL("slow?0").spec();
1692 GoOnTheRecord(); 1696 GoOnTheRecord();
1693 1697
1694 EXPECT_STREQ(download_extension_errors::kInvalidFilenameError, 1698 EXPECT_STREQ(download_extension_errors::kInvalidFilenameError,
1695 RunFunctionAndReturnError(new DownloadsDownloadFunction(), 1699 RunFunctionAndReturnError(new DownloadsDownloadFunction(),
1696 base::StringPrintf( 1700 base::StringPrintf(
1697 "[{\"url\": \"%s\"," 1701 "[{\"url\": \"%s\","
1698 " \"filename\": \"sub/dir/ect/ory.txt\"}]", 1702 " \"filename\": \"sub/dir/ect/ory.txt\"}]",
1699 download_url.c_str())).c_str()); 1703 download_url.c_str())).c_str());
1700 } 1704 }
1701 1705
1702 // Test that invalid filenames are disallowed. 1706 // Test that invalid filenames are disallowed.
1703 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1707 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1704 DownloadExtensionTest_Download_InvalidFilename) { 1708 DownloadExtensionTest_Download_InvalidFilename) {
1705 LoadExtension("downloads_split"); 1709 LoadExtension("downloads_split");
1706 CHECK(StartTestServer()); 1710 ASSERT_TRUE(StartEmbeddedTestServer());
1711 ASSERT_TRUE(test_server()->Start());
1707 std::string download_url = test_server()->GetURL("slow?0").spec(); 1712 std::string download_url = test_server()->GetURL("slow?0").spec();
1708 GoOnTheRecord(); 1713 GoOnTheRecord();
1709 1714
1710 EXPECT_STREQ(download_extension_errors::kInvalidFilenameError, 1715 EXPECT_STREQ(download_extension_errors::kInvalidFilenameError,
1711 RunFunctionAndReturnError(new DownloadsDownloadFunction(), 1716 RunFunctionAndReturnError(new DownloadsDownloadFunction(),
1712 base::StringPrintf( 1717 base::StringPrintf(
1713 "[{\"url\": \"%s\"," 1718 "[{\"url\": \"%s\","
1714 " \"filename\": \"../../../../../etc/passwd\"}]", 1719 " \"filename\": \"../../../../../etc/passwd\"}]",
1715 download_url.c_str())).c_str()); 1720 download_url.c_str())).c_str());
1716 } 1721 }
(...skipping 25 matching lines...) Expand all
1742 } 1747 }
1743 } 1748 }
1744 1749
1745 // TODO(benjhayden): Set up a test ftp server, add ftp://localhost* to 1750 // TODO(benjhayden): Set up a test ftp server, add ftp://localhost* to
1746 // permissions, test downloading from ftp. 1751 // permissions, test downloading from ftp.
1747 1752
1748 // Valid URLs plus fragments are still valid URLs. 1753 // Valid URLs plus fragments are still valid URLs.
1749 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1754 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1750 DownloadExtensionTest_Download_URLFragment) { 1755 DownloadExtensionTest_Download_URLFragment) {
1751 LoadExtension("downloads_split"); 1756 LoadExtension("downloads_split");
1752 CHECK(StartTestServer()); 1757 ASSERT_TRUE(StartEmbeddedTestServer());
1758 ASSERT_TRUE(test_server()->Start());
1753 std::string download_url = test_server()->GetURL("slow?0#fragment").spec(); 1759 std::string download_url = test_server()->GetURL("slow?0#fragment").spec();
1754 GoOnTheRecord(); 1760 GoOnTheRecord();
1755 1761
1756 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 1762 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
1757 new DownloadsDownloadFunction(), base::StringPrintf( 1763 new DownloadsDownloadFunction(), base::StringPrintf(
1758 "[{\"url\": \"%s\"}]", download_url.c_str()))); 1764 "[{\"url\": \"%s\"}]", download_url.c_str())));
1759 ASSERT_TRUE(result.get()); 1765 ASSERT_TRUE(result.get());
1760 int result_id = -1; 1766 int result_id = -1;
1761 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1767 ASSERT_TRUE(result->GetAsInteger(&result_id));
1762 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 1768 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1879 result_id))); 1885 result_id)));
1880 } 1886 }
1881 1887
1882 // Test that auth-basic-succeed would fail if the resource requires the 1888 // Test that auth-basic-succeed would fail if the resource requires the
1883 // Authorization header and chrome fails to propagate it back to the server. 1889 // Authorization header and chrome fails to propagate it back to the server.
1884 // This tests both that testserver.py does not succeed when it should fail as 1890 // This tests both that testserver.py does not succeed when it should fail as
1885 // well as how the downloads extension API exposes the failure to extensions. 1891 // well as how the downloads extension API exposes the failure to extensions.
1886 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1892 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1887 DownloadExtensionTest_Download_AuthBasic_Fail) { 1893 DownloadExtensionTest_Download_AuthBasic_Fail) {
1888 LoadExtension("downloads_split"); 1894 LoadExtension("downloads_split");
1889 CHECK(StartTestServer()); 1895 ASSERT_TRUE(StartEmbeddedTestServer());
1896 ASSERT_TRUE(test_server()->Start());
1890 std::string download_url = test_server()->GetURL("auth-basic").spec(); 1897 std::string download_url = test_server()->GetURL("auth-basic").spec();
1891 GoOnTheRecord(); 1898 GoOnTheRecord();
1892 1899
1893 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 1900 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
1894 new DownloadsDownloadFunction(), base::StringPrintf( 1901 new DownloadsDownloadFunction(), base::StringPrintf(
1895 "[{\"url\": \"%s\"," 1902 "[{\"url\": \"%s\","
1896 " \"filename\": \"auth-basic-fail.txt\"}]", 1903 " \"filename\": \"auth-basic-fail.txt\"}]",
1897 download_url.c_str()))); 1904 download_url.c_str())));
1898 ASSERT_TRUE(result.get()); 1905 ASSERT_TRUE(result.get());
1899 int result_id = -1; 1906 int result_id = -1;
1900 ASSERT_TRUE(result->GetAsInteger(&result_id)); 1907 ASSERT_TRUE(result->GetAsInteger(&result_id));
1901 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 1908 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
1902 ASSERT_TRUE(item); 1909 ASSERT_TRUE(item);
1903 ScopedCancellingItem canceller(item); 1910 ScopedCancellingItem canceller(item);
1904 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 1911 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
1905 1912
1906 ASSERT_TRUE(WaitForInterruption(item, 30, base::StringPrintf( 1913 ASSERT_TRUE(WaitForInterruption(item, 30, base::StringPrintf(
1907 "[{\"danger\": \"safe\"," 1914 "[{\"danger\": \"safe\","
1908 " \"incognito\": false," 1915 " \"incognito\": false,"
1909 " \"mime\": \"text/html\"," 1916 " \"mime\": \"text/html\","
1910 " \"paused\": false," 1917 " \"paused\": false,"
1911 " \"url\": \"%s\"}]", 1918 " \"url\": \"%s\"}]",
1912 download_url.c_str()))); 1919 download_url.c_str())));
1913 } 1920 }
1914 1921
1915 // Test that DownloadsDownloadFunction propagates |headers| to the URLRequest. 1922 // Test that DownloadsDownloadFunction propagates |headers| to the URLRequest.
1916 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1923 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1917 DownloadExtensionTest_Download_Headers) { 1924 DownloadExtensionTest_Download_Headers) {
1918 LoadExtension("downloads_split"); 1925 LoadExtension("downloads_split");
1919 CHECK(StartTestServer()); 1926 ASSERT_TRUE(StartEmbeddedTestServer());
1927 ASSERT_TRUE(test_server()->Start());
1920 std::string download_url = test_server()->GetURL("files/downloads/" 1928 std::string download_url = test_server()->GetURL("files/downloads/"
1921 "a_zip_file.zip?expected_headers=Foo:bar&expected_headers=Qx:yo").spec(); 1929 "a_zip_file.zip?expected_headers=Foo:bar&expected_headers=Qx:yo").spec();
1922 GoOnTheRecord(); 1930 GoOnTheRecord();
1923 1931
1924 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 1932 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
1925 new DownloadsDownloadFunction(), base::StringPrintf( 1933 new DownloadsDownloadFunction(), base::StringPrintf(
1926 "[{\"url\": \"%s\"," 1934 "[{\"url\": \"%s\","
1927 " \"filename\": \"headers-succeed.txt\"," 1935 " \"filename\": \"headers-succeed.txt\","
1928 " \"headers\": [" 1936 " \"headers\": ["
1929 " {\"name\": \"Foo\", \"value\": \"bar\"}," 1937 " {\"name\": \"Foo\", \"value\": \"bar\"},"
(...skipping 29 matching lines...) Expand all
1959 result_id))); 1967 result_id)));
1960 } 1968 }
1961 1969
1962 // Test that headers-succeed would fail if the resource requires the headers and 1970 // Test that headers-succeed would fail if the resource requires the headers and
1963 // chrome fails to propagate them back to the server. This tests both that 1971 // chrome fails to propagate them back to the server. This tests both that
1964 // testserver.py does not succeed when it should fail as well as how the 1972 // testserver.py does not succeed when it should fail as well as how the
1965 // downloads extension api exposes the failure to extensions. 1973 // downloads extension api exposes the failure to extensions.
1966 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1974 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1967 DownloadExtensionTest_Download_Headers_Fail) { 1975 DownloadExtensionTest_Download_Headers_Fail) {
1968 LoadExtension("downloads_split"); 1976 LoadExtension("downloads_split");
1969 CHECK(StartTestServer()); 1977 ASSERT_TRUE(StartEmbeddedTestServer());
1978 ASSERT_TRUE(test_server()->Start());
1970 std::string download_url = test_server()->GetURL("files/downloads/" 1979 std::string download_url = test_server()->GetURL("files/downloads/"
1971 "a_zip_file.zip?expected_headers=Foo:bar&expected_headers=Qx:yo").spec(); 1980 "a_zip_file.zip?expected_headers=Foo:bar&expected_headers=Qx:yo").spec();
1972 GoOnTheRecord(); 1981 GoOnTheRecord();
1973 1982
1974 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 1983 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
1975 new DownloadsDownloadFunction(), base::StringPrintf( 1984 new DownloadsDownloadFunction(), base::StringPrintf(
1976 "[{\"url\": \"%s\"," 1985 "[{\"url\": \"%s\","
1977 " \"filename\": \"headers-fail.txt\"}]", 1986 " \"filename\": \"headers-fail.txt\"}]",
1978 download_url.c_str()))); 1987 download_url.c_str())));
1979 ASSERT_TRUE(result.get()); 1988 ASSERT_TRUE(result.get());
(...skipping 12 matching lines...) Expand all
1992 " \"paused\": false," 2001 " \"paused\": false,"
1993 " \"url\": \"%s\"}]", 2002 " \"url\": \"%s\"}]",
1994 download_url.c_str()))); 2003 download_url.c_str())));
1995 } 2004 }
1996 2005
1997 // Test that DownloadsDownloadFunction propagates the Authorization header 2006 // Test that DownloadsDownloadFunction propagates the Authorization header
1998 // correctly. 2007 // correctly.
1999 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 2008 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
2000 DownloadExtensionTest_Download_AuthBasic) { 2009 DownloadExtensionTest_Download_AuthBasic) {
2001 LoadExtension("downloads_split"); 2010 LoadExtension("downloads_split");
2002 CHECK(StartTestServer()); 2011 ASSERT_TRUE(StartEmbeddedTestServer());
2012 ASSERT_TRUE(test_server()->Start());
2003 std::string download_url = test_server()->GetURL("auth-basic").spec(); 2013 std::string download_url = test_server()->GetURL("auth-basic").spec();
2004 // This is just base64 of 'username:secret'. 2014 // This is just base64 of 'username:secret'.
2005 static const char* kAuthorization = "dXNlcm5hbWU6c2VjcmV0"; 2015 static const char* kAuthorization = "dXNlcm5hbWU6c2VjcmV0";
2006 GoOnTheRecord(); 2016 GoOnTheRecord();
2007 2017
2008 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2018 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2009 new DownloadsDownloadFunction(), base::StringPrintf( 2019 new DownloadsDownloadFunction(), base::StringPrintf(
2010 "[{\"url\": \"%s\"," 2020 "[{\"url\": \"%s\","
2011 " \"filename\": \"auth-basic-succeed.txt\"," 2021 " \"filename\": \"auth-basic-succeed.txt\","
2012 " \"headers\": [{" 2022 " \"headers\": [{"
(...skipping 19 matching lines...) Expand all
2032 " \"state\": {" 2042 " \"state\": {"
2033 " \"previous\": \"in_progress\"," 2043 " \"previous\": \"in_progress\","
2034 " \"current\": \"complete\"}}]", result_id))); 2044 " \"current\": \"complete\"}}]", result_id)));
2035 } 2045 }
2036 2046
2037 // Test that DownloadsDownloadFunction propagates the |method| and |body| 2047 // Test that DownloadsDownloadFunction propagates the |method| and |body|
2038 // parameters to the URLRequest. 2048 // parameters to the URLRequest.
2039 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 2049 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
2040 DownloadExtensionTest_Download_Post) { 2050 DownloadExtensionTest_Download_Post) {
2041 LoadExtension("downloads_split"); 2051 LoadExtension("downloads_split");
2042 CHECK(StartTestServer()); 2052 ASSERT_TRUE(StartEmbeddedTestServer());
2053 ASSERT_TRUE(test_server()->Start());
2043 std::string download_url = test_server()->GetURL("files/post/downloads/" 2054 std::string download_url = test_server()->GetURL("files/post/downloads/"
2044 "a_zip_file.zip?expected_body=BODY").spec(); 2055 "a_zip_file.zip?expected_body=BODY").spec();
2045 GoOnTheRecord(); 2056 GoOnTheRecord();
2046 2057
2047 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2058 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2048 new DownloadsDownloadFunction(), base::StringPrintf( 2059 new DownloadsDownloadFunction(), base::StringPrintf(
2049 "[{\"url\": \"%s\"," 2060 "[{\"url\": \"%s\","
2050 " \"filename\": \"post-succeed.txt\"," 2061 " \"filename\": \"post-succeed.txt\","
2051 " \"method\": \"POST\"," 2062 " \"method\": \"POST\","
2052 " \"body\": \"BODY\"}]", 2063 " \"body\": \"BODY\"}]",
(...skipping 28 matching lines...) Expand all
2081 } 2092 }
2082 2093
2083 // Test that downloadPostSuccess would fail if the resource requires the POST 2094 // Test that downloadPostSuccess would fail if the resource requires the POST
2084 // method, and chrome fails to propagate the |method| parameter back to the 2095 // method, and chrome fails to propagate the |method| parameter back to the
2085 // server. This tests both that testserver.py does not succeed when it should 2096 // server. This tests both that testserver.py does not succeed when it should
2086 // fail, and this tests how the downloads extension api exposes the failure to 2097 // fail, and this tests how the downloads extension api exposes the failure to
2087 // extensions. 2098 // extensions.
2088 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 2099 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
2089 DownloadExtensionTest_Download_Post_Get) { 2100 DownloadExtensionTest_Download_Post_Get) {
2090 LoadExtension("downloads_split"); 2101 LoadExtension("downloads_split");
2091 CHECK(StartTestServer()); 2102 ASSERT_TRUE(StartEmbeddedTestServer());
2103 ASSERT_TRUE(test_server()->Start());
2092 std::string download_url = test_server()->GetURL("files/post/downloads/" 2104 std::string download_url = test_server()->GetURL("files/post/downloads/"
2093 "a_zip_file.zip?expected_body=BODY").spec(); 2105 "a_zip_file.zip?expected_body=BODY").spec();
2094 GoOnTheRecord(); 2106 GoOnTheRecord();
2095 2107
2096 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2108 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2097 new DownloadsDownloadFunction(), base::StringPrintf( 2109 new DownloadsDownloadFunction(), base::StringPrintf(
2098 "[{\"url\": \"%s\"," 2110 "[{\"url\": \"%s\","
2099 " \"body\": \"BODY\"," 2111 " \"body\": \"BODY\","
2100 " \"filename\": \"post-get.txt\"}]", 2112 " \"filename\": \"post-get.txt\"}]",
2101 download_url.c_str()))); 2113 download_url.c_str())));
(...skipping 17 matching lines...) Expand all
2119 } 2131 }
2120 2132
2121 // Test that downloadPostSuccess would fail if the resource requires the POST 2133 // Test that downloadPostSuccess would fail if the resource requires the POST
2122 // method, and chrome fails to propagate the |body| parameter back to the 2134 // method, and chrome fails to propagate the |body| parameter back to the
2123 // server. This tests both that testserver.py does not succeed when it should 2135 // server. This tests both that testserver.py does not succeed when it should
2124 // fail, and this tests how the downloads extension api exposes the failure to 2136 // fail, and this tests how the downloads extension api exposes the failure to
2125 // extensions. 2137 // extensions.
2126 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 2138 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
2127 DownloadExtensionTest_Download_Post_NoBody) { 2139 DownloadExtensionTest_Download_Post_NoBody) {
2128 LoadExtension("downloads_split"); 2140 LoadExtension("downloads_split");
2129 CHECK(StartTestServer()); 2141 ASSERT_TRUE(StartEmbeddedTestServer());
2142 ASSERT_TRUE(test_server()->Start());
2130 std::string download_url = test_server()->GetURL("files/post/downloads/" 2143 std::string download_url = test_server()->GetURL("files/post/downloads/"
2131 "a_zip_file.zip?expected_body=BODY").spec(); 2144 "a_zip_file.zip?expected_body=BODY").spec();
2132 GoOnTheRecord(); 2145 GoOnTheRecord();
2133 2146
2134 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2147 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2135 new DownloadsDownloadFunction(), base::StringPrintf( 2148 new DownloadsDownloadFunction(), base::StringPrintf(
2136 "[{\"url\": \"%s\"," 2149 "[{\"url\": \"%s\","
2137 " \"method\": \"POST\"," 2150 " \"method\": \"POST\","
2138 " \"filename\": \"post-nobody.txt\"}]", 2151 " \"filename\": \"post-nobody.txt\"}]",
2139 download_url.c_str()))); 2152 download_url.c_str())));
(...skipping 16 matching lines...) Expand all
2156 download_url.c_str()))); 2169 download_url.c_str())));
2157 } 2170 }
2158 2171
2159 // Test that cancel()ing an in-progress download causes its state to transition 2172 // Test that cancel()ing an in-progress download causes its state to transition
2160 // to interrupted, and test that that state transition is detectable by an 2173 // to interrupted, and test that that state transition is detectable by an
2161 // onChanged event listener. TODO(benjhayden): Test other sources of 2174 // onChanged event listener. TODO(benjhayden): Test other sources of
2162 // interruptions such as server death. 2175 // interruptions such as server death.
2163 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 2176 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
2164 DownloadExtensionTest_Download_Cancel) { 2177 DownloadExtensionTest_Download_Cancel) {
2165 LoadExtension("downloads_split"); 2178 LoadExtension("downloads_split");
2166 CHECK(StartTestServer()); 2179 ASSERT_TRUE(StartEmbeddedTestServer());
2180 ASSERT_TRUE(test_server()->Start());
2167 std::string download_url = test_server()->GetURL( 2181 std::string download_url = test_server()->GetURL(
2168 "download-known-size").spec(); 2182 "download-known-size").spec();
2169 GoOnTheRecord(); 2183 GoOnTheRecord();
2170 2184
2171 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2185 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2172 new DownloadsDownloadFunction(), base::StringPrintf( 2186 new DownloadsDownloadFunction(), base::StringPrintf(
2173 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2187 "[{\"url\": \"%s\"}]", download_url.c_str())));
2174 ASSERT_TRUE(result.get()); 2188 ASSERT_TRUE(result.get());
2175 int result_id = -1; 2189 int result_id = -1;
2176 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2190 ASSERT_TRUE(result->GetAsInteger(&result_id));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2251 EXPECT_TRUE(file_util::ReadFileToString(item->GetTargetFilePath(), 2265 EXPECT_TRUE(file_util::ReadFileToString(item->GetTargetFilePath(),
2252 &disk_data)); 2266 &disk_data));
2253 EXPECT_STREQ(kPayloadData, disk_data.c_str()); 2267 EXPECT_STREQ(kPayloadData, disk_data.c_str());
2254 } 2268 }
2255 2269
2256 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 2270 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
2257 DownloadExtensionTest_OnDeterminingFilename_NoChange) { 2271 DownloadExtensionTest_OnDeterminingFilename_NoChange) {
2258 GoOnTheRecord(); 2272 GoOnTheRecord();
2259 LoadExtension("downloads_split"); 2273 LoadExtension("downloads_split");
2260 AddFilenameDeterminer(); 2274 AddFilenameDeterminer();
2261 CHECK(StartTestServer()); 2275 ASSERT_TRUE(StartEmbeddedTestServer());
2276 ASSERT_TRUE(test_server()->Start());
2262 std::string download_url = test_server()->GetURL("slow?0").spec(); 2277 std::string download_url = test_server()->GetURL("slow?0").spec();
2263 2278
2264 // Start downloading a file. 2279 // Start downloading a file.
2265 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2280 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2266 new DownloadsDownloadFunction(), base::StringPrintf( 2281 new DownloadsDownloadFunction(), base::StringPrintf(
2267 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2282 "[{\"url\": \"%s\"}]", download_url.c_str())));
2268 ASSERT_TRUE(result.get()); 2283 ASSERT_TRUE(result.get());
2269 int result_id = -1; 2284 int result_id = -1;
2270 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2285 ASSERT_TRUE(result->GetAsInteger(&result_id));
2271 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2286 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2318 " \"current\": \"complete\"}}]", 2333 " \"current\": \"complete\"}}]",
2319 result_id))); 2334 result_id)));
2320 } 2335 }
2321 2336
2322 IN_PROC_BROWSER_TEST_F( 2337 IN_PROC_BROWSER_TEST_F(
2323 DownloadExtensionTest, 2338 DownloadExtensionTest,
2324 DownloadExtensionTest_OnDeterminingFilename_DangerousOverride) { 2339 DownloadExtensionTest_OnDeterminingFilename_DangerousOverride) {
2325 GoOnTheRecord(); 2340 GoOnTheRecord();
2326 LoadExtension("downloads_split"); 2341 LoadExtension("downloads_split");
2327 AddFilenameDeterminer(); 2342 AddFilenameDeterminer();
2328 CHECK(StartTestServer()); 2343 ASSERT_TRUE(StartEmbeddedTestServer());
2344 ASSERT_TRUE(test_server()->Start());
2329 std::string download_url = test_server()->GetURL("slow?0").spec(); 2345 std::string download_url = test_server()->GetURL("slow?0").spec();
2330 2346
2331 // Start downloading a file. 2347 // Start downloading a file.
2332 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2348 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2333 new DownloadsDownloadFunction(), base::StringPrintf( 2349 new DownloadsDownloadFunction(), base::StringPrintf(
2334 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2350 "[{\"url\": \"%s\"}]", download_url.c_str())));
2335 ASSERT_TRUE(result.get()); 2351 ASSERT_TRUE(result.get());
2336 int result_id = -1; 2352 int result_id = -1;
2337 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2353 ASSERT_TRUE(result->GetAsInteger(&result_id));
2338 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2354 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2394 EXPECT_EQ(downloads_directory().AppendASCII("overridden.swf"), 2410 EXPECT_EQ(downloads_directory().AppendASCII("overridden.swf"),
2395 item->GetTargetFilePath()); 2411 item->GetTargetFilePath());
2396 } 2412 }
2397 2413
2398 IN_PROC_BROWSER_TEST_F( 2414 IN_PROC_BROWSER_TEST_F(
2399 DownloadExtensionTest, 2415 DownloadExtensionTest,
2400 DownloadExtensionTest_OnDeterminingFilename_ReferencesParentInvalid) { 2416 DownloadExtensionTest_OnDeterminingFilename_ReferencesParentInvalid) {
2401 GoOnTheRecord(); 2417 GoOnTheRecord();
2402 LoadExtension("downloads_split"); 2418 LoadExtension("downloads_split");
2403 AddFilenameDeterminer(); 2419 AddFilenameDeterminer();
2404 CHECK(StartTestServer()); 2420 ASSERT_TRUE(StartEmbeddedTestServer());
2421 ASSERT_TRUE(test_server()->Start());
2405 std::string download_url = test_server()->GetURL("slow?0").spec(); 2422 std::string download_url = test_server()->GetURL("slow?0").spec();
2406 2423
2407 // Start downloading a file. 2424 // Start downloading a file.
2408 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2425 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2409 new DownloadsDownloadFunction(), base::StringPrintf( 2426 new DownloadsDownloadFunction(), base::StringPrintf(
2410 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2427 "[{\"url\": \"%s\"}]", download_url.c_str())));
2411 ASSERT_TRUE(result.get()); 2428 ASSERT_TRUE(result.get());
2412 int result_id = -1; 2429 int result_id = -1;
2413 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2430 ASSERT_TRUE(result->GetAsInteger(&result_id));
2414 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2431 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2458 " \"current\": \"complete\"}}]", 2475 " \"current\": \"complete\"}}]",
2459 result_id))); 2476 result_id)));
2460 } 2477 }
2461 2478
2462 IN_PROC_BROWSER_TEST_F( 2479 IN_PROC_BROWSER_TEST_F(
2463 DownloadExtensionTest, 2480 DownloadExtensionTest,
2464 DownloadExtensionTest_OnDeterminingFilename_IllegalFilename) { 2481 DownloadExtensionTest_OnDeterminingFilename_IllegalFilename) {
2465 GoOnTheRecord(); 2482 GoOnTheRecord();
2466 LoadExtension("downloads_split"); 2483 LoadExtension("downloads_split");
2467 AddFilenameDeterminer(); 2484 AddFilenameDeterminer();
2468 CHECK(StartTestServer()); 2485 ASSERT_TRUE(StartEmbeddedTestServer());
2486 ASSERT_TRUE(test_server()->Start());
2469 std::string download_url = test_server()->GetURL("slow?0").spec(); 2487 std::string download_url = test_server()->GetURL("slow?0").spec();
2470 2488
2471 // Start downloading a file. 2489 // Start downloading a file.
2472 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2490 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2473 new DownloadsDownloadFunction(), base::StringPrintf( 2491 new DownloadsDownloadFunction(), base::StringPrintf(
2474 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2492 "[{\"url\": \"%s\"}]", download_url.c_str())));
2475 ASSERT_TRUE(result.get()); 2493 ASSERT_TRUE(result.get());
2476 int result_id = -1; 2494 int result_id = -1;
2477 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2495 ASSERT_TRUE(result->GetAsInteger(&result_id));
2478 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2496 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2522 " \"current\": \"complete\"}}]", 2540 " \"current\": \"complete\"}}]",
2523 result_id))); 2541 result_id)));
2524 } 2542 }
2525 2543
2526 IN_PROC_BROWSER_TEST_F( 2544 IN_PROC_BROWSER_TEST_F(
2527 DownloadExtensionTest, 2545 DownloadExtensionTest,
2528 DownloadExtensionTest_OnDeterminingFilename_IllegalFilenameExtension) { 2546 DownloadExtensionTest_OnDeterminingFilename_IllegalFilenameExtension) {
2529 GoOnTheRecord(); 2547 GoOnTheRecord();
2530 LoadExtension("downloads_split"); 2548 LoadExtension("downloads_split");
2531 AddFilenameDeterminer(); 2549 AddFilenameDeterminer();
2532 CHECK(StartTestServer()); 2550 ASSERT_TRUE(StartEmbeddedTestServer());
2551 ASSERT_TRUE(test_server()->Start());
2533 std::string download_url = test_server()->GetURL("slow?0").spec(); 2552 std::string download_url = test_server()->GetURL("slow?0").spec();
2534 2553
2535 // Start downloading a file. 2554 // Start downloading a file.
2536 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2555 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2537 new DownloadsDownloadFunction(), base::StringPrintf( 2556 new DownloadsDownloadFunction(), base::StringPrintf(
2538 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2557 "[{\"url\": \"%s\"}]", download_url.c_str())));
2539 ASSERT_TRUE(result.get()); 2558 ASSERT_TRUE(result.get());
2540 int result_id = -1; 2559 int result_id = -1;
2541 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2560 ASSERT_TRUE(result->GetAsInteger(&result_id));
2542 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2561 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2587 " \"current\": \"complete\"}}]", 2606 " \"current\": \"complete\"}}]",
2588 result_id))); 2607 result_id)));
2589 } 2608 }
2590 2609
2591 IN_PROC_BROWSER_TEST_F( 2610 IN_PROC_BROWSER_TEST_F(
2592 DownloadExtensionTest, 2611 DownloadExtensionTest,
2593 DownloadExtensionTest_OnDeterminingFilename_ReservedFilename) { 2612 DownloadExtensionTest_OnDeterminingFilename_ReservedFilename) {
2594 GoOnTheRecord(); 2613 GoOnTheRecord();
2595 LoadExtension("downloads_split"); 2614 LoadExtension("downloads_split");
2596 AddFilenameDeterminer(); 2615 AddFilenameDeterminer();
2597 CHECK(StartTestServer()); 2616 ASSERT_TRUE(StartEmbeddedTestServer());
2617 ASSERT_TRUE(test_server()->Start());
2598 std::string download_url = test_server()->GetURL("slow?0").spec(); 2618 std::string download_url = test_server()->GetURL("slow?0").spec();
2599 2619
2600 // Start downloading a file. 2620 // Start downloading a file.
2601 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2621 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2602 new DownloadsDownloadFunction(), base::StringPrintf( 2622 new DownloadsDownloadFunction(), base::StringPrintf(
2603 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2623 "[{\"url\": \"%s\"}]", download_url.c_str())));
2604 ASSERT_TRUE(result.get()); 2624 ASSERT_TRUE(result.get());
2605 int result_id = -1; 2625 int result_id = -1;
2606 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2626 ASSERT_TRUE(result->GetAsInteger(&result_id));
2607 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2627 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2651 " \"current\": \"complete\"}}]", 2671 " \"current\": \"complete\"}}]",
2652 result_id))); 2672 result_id)));
2653 } 2673 }
2654 2674
2655 IN_PROC_BROWSER_TEST_F( 2675 IN_PROC_BROWSER_TEST_F(
2656 DownloadExtensionTest, 2676 DownloadExtensionTest,
2657 DownloadExtensionTest_OnDeterminingFilename_CurDirInvalid) { 2677 DownloadExtensionTest_OnDeterminingFilename_CurDirInvalid) {
2658 GoOnTheRecord(); 2678 GoOnTheRecord();
2659 LoadExtension("downloads_split"); 2679 LoadExtension("downloads_split");
2660 AddFilenameDeterminer(); 2680 AddFilenameDeterminer();
2661 CHECK(StartTestServer()); 2681 ASSERT_TRUE(StartEmbeddedTestServer());
2682 ASSERT_TRUE(test_server()->Start());
2662 std::string download_url = test_server()->GetURL("slow?0").spec(); 2683 std::string download_url = test_server()->GetURL("slow?0").spec();
2663 2684
2664 // Start downloading a file. 2685 // Start downloading a file.
2665 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2686 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2666 new DownloadsDownloadFunction(), base::StringPrintf( 2687 new DownloadsDownloadFunction(), base::StringPrintf(
2667 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2688 "[{\"url\": \"%s\"}]", download_url.c_str())));
2668 ASSERT_TRUE(result.get()); 2689 ASSERT_TRUE(result.get());
2669 int result_id = -1; 2690 int result_id = -1;
2670 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2691 ASSERT_TRUE(result->GetAsInteger(&result_id));
2671 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2692 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2712 base::StringPrintf("[{\"id\": %d," 2733 base::StringPrintf("[{\"id\": %d,"
2713 " \"state\": {" 2734 " \"state\": {"
2714 " \"previous\": \"in_progress\"," 2735 " \"previous\": \"in_progress\","
2715 " \"current\": \"complete\"}}]", 2736 " \"current\": \"complete\"}}]",
2716 result_id))); 2737 result_id)));
2717 } 2738 }
2718 2739
2719 IN_PROC_BROWSER_TEST_F( 2740 IN_PROC_BROWSER_TEST_F(
2720 DownloadExtensionTest, 2741 DownloadExtensionTest,
2721 DownloadExtensionTest_OnDeterminingFilename_ParentDirInvalid) { 2742 DownloadExtensionTest_OnDeterminingFilename_ParentDirInvalid) {
2722 CHECK(StartTestServer()); 2743 ASSERT_TRUE(StartEmbeddedTestServer());
2744 ASSERT_TRUE(test_server()->Start());
2723 GoOnTheRecord(); 2745 GoOnTheRecord();
2724 LoadExtension("downloads_split"); 2746 LoadExtension("downloads_split");
2725 AddFilenameDeterminer(); 2747 AddFilenameDeterminer();
2726 std::string download_url = test_server()->GetURL("slow?0").spec(); 2748 std::string download_url = test_server()->GetURL("slow?0").spec();
2727 2749
2728 // Start downloading a file. 2750 // Start downloading a file.
2729 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2751 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2730 new DownloadsDownloadFunction(), base::StringPrintf( 2752 new DownloadsDownloadFunction(), base::StringPrintf(
2731 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2753 "[{\"url\": \"%s\"}]", download_url.c_str())));
2732 ASSERT_TRUE(result.get()); 2754 ASSERT_TRUE(result.get());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2779 " \"current\": \"complete\"}}]", 2801 " \"current\": \"complete\"}}]",
2780 result_id))); 2802 result_id)));
2781 } 2803 }
2782 2804
2783 IN_PROC_BROWSER_TEST_F( 2805 IN_PROC_BROWSER_TEST_F(
2784 DownloadExtensionTest, 2806 DownloadExtensionTest,
2785 DownloadExtensionTest_OnDeterminingFilename_AbsPathInvalid) { 2807 DownloadExtensionTest_OnDeterminingFilename_AbsPathInvalid) {
2786 GoOnTheRecord(); 2808 GoOnTheRecord();
2787 LoadExtension("downloads_split"); 2809 LoadExtension("downloads_split");
2788 AddFilenameDeterminer(); 2810 AddFilenameDeterminer();
2789 CHECK(StartTestServer()); 2811 ASSERT_TRUE(StartEmbeddedTestServer());
2812 ASSERT_TRUE(test_server()->Start());
2790 std::string download_url = test_server()->GetURL("slow?0").spec(); 2813 std::string download_url = test_server()->GetURL("slow?0").spec();
2791 2814
2792 // Start downloading a file. 2815 // Start downloading a file.
2793 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2816 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2794 new DownloadsDownloadFunction(), base::StringPrintf( 2817 new DownloadsDownloadFunction(), base::StringPrintf(
2795 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2818 "[{\"url\": \"%s\"}]", download_url.c_str())));
2796 ASSERT_TRUE(result.get()); 2819 ASSERT_TRUE(result.get());
2797 int result_id = -1; 2820 int result_id = -1;
2798 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2821 ASSERT_TRUE(result->GetAsInteger(&result_id));
2799 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2822 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2844 " \"current\": \"complete\"}}]", 2867 " \"current\": \"complete\"}}]",
2845 result_id))); 2868 result_id)));
2846 } 2869 }
2847 2870
2848 IN_PROC_BROWSER_TEST_F( 2871 IN_PROC_BROWSER_TEST_F(
2849 DownloadExtensionTest, 2872 DownloadExtensionTest,
2850 DownloadExtensionTest_OnDeterminingFilename_EmptyBasenameInvalid) { 2873 DownloadExtensionTest_OnDeterminingFilename_EmptyBasenameInvalid) {
2851 GoOnTheRecord(); 2874 GoOnTheRecord();
2852 LoadExtension("downloads_split"); 2875 LoadExtension("downloads_split");
2853 AddFilenameDeterminer(); 2876 AddFilenameDeterminer();
2854 CHECK(StartTestServer()); 2877 ASSERT_TRUE(StartEmbeddedTestServer());
2878 ASSERT_TRUE(test_server()->Start());
2855 std::string download_url = test_server()->GetURL("slow?0").spec(); 2879 std::string download_url = test_server()->GetURL("slow?0").spec();
2856 2880
2857 // Start downloading a file. 2881 // Start downloading a file.
2858 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2882 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2859 new DownloadsDownloadFunction(), base::StringPrintf( 2883 new DownloadsDownloadFunction(), base::StringPrintf(
2860 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2884 "[{\"url\": \"%s\"}]", download_url.c_str())));
2861 ASSERT_TRUE(result.get()); 2885 ASSERT_TRUE(result.get());
2862 int result_id = -1; 2886 int result_id = -1;
2863 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2887 ASSERT_TRUE(result->GetAsInteger(&result_id));
2864 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2888 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2909 " \"current\": \"complete\"}}]", 2933 " \"current\": \"complete\"}}]",
2910 result_id))); 2934 result_id)));
2911 } 2935 }
2912 2936
2913 IN_PROC_BROWSER_TEST_F( 2937 IN_PROC_BROWSER_TEST_F(
2914 DownloadExtensionTest, 2938 DownloadExtensionTest,
2915 DownloadExtensionTest_OnDeterminingFilename_Override) { 2939 DownloadExtensionTest_OnDeterminingFilename_Override) {
2916 GoOnTheRecord(); 2940 GoOnTheRecord();
2917 LoadExtension("downloads_split"); 2941 LoadExtension("downloads_split");
2918 AddFilenameDeterminer(); 2942 AddFilenameDeterminer();
2919 CHECK(StartTestServer()); 2943 ASSERT_TRUE(StartEmbeddedTestServer());
2944 ASSERT_TRUE(test_server()->Start());
2920 std::string download_url = test_server()->GetURL("slow?0").spec(); 2945 std::string download_url = test_server()->GetURL("slow?0").spec();
2921 2946
2922 // Start downloading a file. 2947 // Start downloading a file.
2923 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 2948 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
2924 new DownloadsDownloadFunction(), base::StringPrintf( 2949 new DownloadsDownloadFunction(), base::StringPrintf(
2925 "[{\"url\": \"%s\"}]", download_url.c_str()))); 2950 "[{\"url\": \"%s\"}]", download_url.c_str())));
2926 ASSERT_TRUE(result.get()); 2951 ASSERT_TRUE(result.get());
2927 int result_id = -1; 2952 int result_id = -1;
2928 ASSERT_TRUE(result->GetAsInteger(&result_id)); 2953 ASSERT_TRUE(result->GetAsInteger(&result_id));
2929 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2954 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
3030 " \"previous\": \"in_progress\"," 3055 " \"previous\": \"in_progress\","
3031 " \"current\": \"complete\"}}]", 3056 " \"current\": \"complete\"}}]",
3032 result_id))); 3057 result_id)));
3033 } 3058 }
3034 3059
3035 // TODO test precedence rules: install_time 3060 // TODO test precedence rules: install_time
3036 3061
3037 IN_PROC_BROWSER_TEST_F( 3062 IN_PROC_BROWSER_TEST_F(
3038 DownloadExtensionTest, 3063 DownloadExtensionTest,
3039 DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDeterminer) { 3064 DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDeterminer) {
3040 CHECK(StartTestServer()); 3065 ASSERT_TRUE(StartEmbeddedTestServer());
3066 ASSERT_TRUE(test_server()->Start());
3041 GoOnTheRecord(); 3067 GoOnTheRecord();
3042 LoadExtension("downloads_split"); 3068 LoadExtension("downloads_split");
3043 content::RenderProcessHost* host = AddFilenameDeterminer(); 3069 content::RenderProcessHost* host = AddFilenameDeterminer();
3044 std::string download_url = test_server()->GetURL("slow?0").spec(); 3070 std::string download_url = test_server()->GetURL("slow?0").spec();
3045 3071
3046 // Start downloading a file. 3072 // Start downloading a file.
3047 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( 3073 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
3048 new DownloadsDownloadFunction(), base::StringPrintf( 3074 new DownloadsDownloadFunction(), base::StringPrintf(
3049 "[{\"url\": \"%s\"}]", download_url.c_str()))); 3075 "[{\"url\": \"%s\"}]", download_url.c_str())));
3050 ASSERT_TRUE(result.get()); 3076 ASSERT_TRUE(result.get());
(...skipping 29 matching lines...) Expand all
3080 " \"state\": {" 3106 " \"state\": {"
3081 " \"previous\": \"in_progress\"," 3107 " \"previous\": \"in_progress\","
3082 " \"current\": \"complete\"}}]", 3108 " \"current\": \"complete\"}}]",
3083 result_id))); 3109 result_id)));
3084 } 3110 }
3085 3111
3086 IN_PROC_BROWSER_TEST_F( 3112 IN_PROC_BROWSER_TEST_F(
3087 DownloadExtensionTest, 3113 DownloadExtensionTest,
3088 DownloadExtensionTest_OnDeterminingFilename_IncognitoSplit) { 3114 DownloadExtensionTest_OnDeterminingFilename_IncognitoSplit) {
3089 LoadExtension("downloads_split"); 3115 LoadExtension("downloads_split");
3090 CHECK(StartTestServer()); 3116 ASSERT_TRUE(StartEmbeddedTestServer());
3117 ASSERT_TRUE(test_server()->Start());
3091 std::string download_url = test_server()->GetURL("slow?0").spec(); 3118 std::string download_url = test_server()->GetURL("slow?0").spec();
3092 3119
3093 GoOnTheRecord(); 3120 GoOnTheRecord();
3094 AddFilenameDeterminer(); 3121 AddFilenameDeterminer();
3095 3122
3096 GoOffTheRecord(); 3123 GoOffTheRecord();
3097 AddFilenameDeterminer(); 3124 AddFilenameDeterminer();
3098 3125
3099 // Start an on-record download. 3126 // Start an on-record download.
3100 GoOnTheRecord(); 3127 GoOnTheRecord();
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
3212 " \"state\": {" 3239 " \"state\": {"
3213 " \"previous\": \"in_progress\"," 3240 " \"previous\": \"in_progress\","
3214 " \"current\": \"complete\"}}]", 3241 " \"current\": \"complete\"}}]",
3215 result_id))); 3242 result_id)));
3216 } 3243 }
3217 3244
3218 IN_PROC_BROWSER_TEST_F( 3245 IN_PROC_BROWSER_TEST_F(
3219 DownloadExtensionTest, 3246 DownloadExtensionTest,
3220 DownloadExtensionTest_OnDeterminingFilename_IncognitoSpanning) { 3247 DownloadExtensionTest_OnDeterminingFilename_IncognitoSpanning) {
3221 LoadExtension("downloads_spanning"); 3248 LoadExtension("downloads_spanning");
3222 CHECK(StartTestServer()); 3249 ASSERT_TRUE(StartEmbeddedTestServer());
3250 ASSERT_TRUE(test_server()->Start());
3223 std::string download_url = test_server()->GetURL("slow?0").spec(); 3251 std::string download_url = test_server()->GetURL("slow?0").spec();
3224 3252
3225 GoOnTheRecord(); 3253 GoOnTheRecord();
3226 AddFilenameDeterminer(); 3254 AddFilenameDeterminer();
3227 3255
3228 // There is a single extension renderer that sees both on-record and 3256 // There is a single extension renderer that sees both on-record and
3229 // off-record events. The extension functions see the on-record profile with 3257 // off-record events. The extension functions see the on-record profile with
3230 // include_incognito=true. 3258 // include_incognito=true.
3231 3259
3232 // Start an on-record download. 3260 // Start an on-record download.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
3357 #endif 3385 #endif
3358 3386
3359 // Test download interruption while extensions determining filename. Should not 3387 // Test download interruption while extensions determining filename. Should not
3360 // re-dispatch onDeterminingFilename. 3388 // re-dispatch onDeterminingFilename.
3361 IN_PROC_BROWSER_TEST_F( 3389 IN_PROC_BROWSER_TEST_F(
3362 DownloadExtensionTest, 3390 DownloadExtensionTest,
3363 MAYBE_DownloadExtensionTest_OnDeterminingFilename_InterruptedResume) { 3391 MAYBE_DownloadExtensionTest_OnDeterminingFilename_InterruptedResume) {
3364 CommandLine::ForCurrentProcess()->AppendSwitch( 3392 CommandLine::ForCurrentProcess()->AppendSwitch(
3365 switches::kEnableDownloadResumption); 3393 switches::kEnableDownloadResumption);
3366 LoadExtension("downloads_split"); 3394 LoadExtension("downloads_split");
3367 CHECK(StartTestServer()); 3395 ASSERT_TRUE(StartEmbeddedTestServer());
3396 ASSERT_TRUE(test_server()->Start());
3368 GoOnTheRecord(); 3397 GoOnTheRecord();
3369 content::RenderProcessHost* host = AddFilenameDeterminer(); 3398 content::RenderProcessHost* host = AddFilenameDeterminer();
3370 3399
3371 // Start a download. 3400 // Start a download.
3372 DownloadItem* item = NULL; 3401 DownloadItem* item = NULL;
3373 { 3402 {
3374 DownloadManager* manager = GetCurrentManager(); 3403 DownloadManager* manager = GetCurrentManager();
3375 scoped_ptr<content::DownloadTestObserver> observer( 3404 scoped_ptr<content::DownloadTestObserver> observer(
3376 new JustInProgressDownloadObserver(manager, 1)); 3405 new JustInProgressDownloadObserver(manager, 1));
3377 ASSERT_EQ(0, manager->InProgressCount()); 3406 ASSERT_EQ(0, manager->InProgressCount());
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
3496 DownloadsApiTest() {} 3525 DownloadsApiTest() {}
3497 virtual ~DownloadsApiTest() {} 3526 virtual ~DownloadsApiTest() {}
3498 private: 3527 private:
3499 DISALLOW_COPY_AND_ASSIGN(DownloadsApiTest); 3528 DISALLOW_COPY_AND_ASSIGN(DownloadsApiTest);
3500 }; 3529 };
3501 3530
3502 3531
3503 IN_PROC_BROWSER_TEST_F(DownloadsApiTest, DownloadsApiTest) { 3532 IN_PROC_BROWSER_TEST_F(DownloadsApiTest, DownloadsApiTest) {
3504 ASSERT_TRUE(RunExtensionTest("downloads")) << message_; 3533 ASSERT_TRUE(RunExtensionTest("downloads")) << message_;
3505 } 3534 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698