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

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

Issue 148133007: [Downloads] Always call DM::StartDownload() for explicit downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typos Created 4 years, 10 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 // 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
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 1715 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 }; 1760 };
1760 1761
1761 for (size_t index = 0; index < arraysize(kInvalidURLs); ++index) { 1762 for (size_t index = 0; index < arraysize(kInvalidURLs); ++index) {
1762 EXPECT_STREQ(errors::kInvalidURL, 1763 EXPECT_STREQ(errors::kInvalidURL,
1763 RunFunctionAndReturnError(new DownloadsDownloadFunction(), 1764 RunFunctionAndReturnError(new DownloadsDownloadFunction(),
1764 base::StringPrintf( 1765 base::StringPrintf(
1765 "[{\"url\": \"%s\"}]", kInvalidURLs[index])).c_str()) 1766 "[{\"url\": \"%s\"}]", kInvalidURLs[index])).c_str())
1766 << kInvalidURLs[index]; 1767 << kInvalidURLs[index];
1767 } 1768 }
1768 1769
1769 EXPECT_STREQ("NETWORK_INVALID_REQUEST", RunFunctionAndReturnError( 1770 int result_id = -1;
1771 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
1770 new DownloadsDownloadFunction(), 1772 new DownloadsDownloadFunction(),
1771 "[{\"url\": \"javascript:document.write(\\\"hello\\\");\"}]").c_str()); 1773 "[{\"url\": \"javascript:document.write(\\\"hello\\\");\"}]"));
1772 EXPECT_STREQ("NETWORK_INVALID_REQUEST", RunFunctionAndReturnError( 1774 ASSERT_TRUE(result.get());
1775 ASSERT_TRUE(result->GetAsInteger(&result_id));
1776 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
1777 ASSERT_TRUE(item);
1778 ASSERT_TRUE(WaitForInterruption(
1779 item, content::DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST,
1780 "[{\"state\": \"in_progress\","
1781 " \"url\": \"javascript:document.write(\\\"hello\\\");\"}]"));
1782
1783 result.reset(
1784 RunFunctionAndReturnResult(new DownloadsDownloadFunction(),
1785 "[{\"url\": \"javascript:return false;\"}]"));
1786 ASSERT_TRUE(result.get());
1787 ASSERT_TRUE(result->GetAsInteger(&result_id));
1788 item = GetCurrentManager()->GetDownload(result_id);
1789 ASSERT_TRUE(item);
1790 ASSERT_TRUE(WaitForInterruption(
1791 item, content::DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST,
1792 "[{\"state\": \"in_progress\","
1793 " \"url\": \"javascript:return false;\"}]"));
1794
1795 result.reset(RunFunctionAndReturnResult(
1773 new DownloadsDownloadFunction(), 1796 new DownloadsDownloadFunction(),
1774 "[{\"url\": \"javascript:return false;\"}]").c_str()); 1797 "[{\"url\": \"ftp://example.com/example.txt\"}]"));
1775 EXPECT_STREQ("NETWORK_FAILED", RunFunctionAndReturnError( 1798 ASSERT_TRUE(result.get());
1776 new DownloadsDownloadFunction(), 1799 ASSERT_TRUE(result->GetAsInteger(&result_id));
1777 "[{\"url\": \"ftp://example.com/example.txt\"}]").c_str()); 1800 item = GetCurrentManager()->GetDownload(result_id);
1801 ASSERT_TRUE(item);
1802 ASSERT_TRUE(WaitForInterruption(
1803 item, content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED,
1804 "[{\"state\": \"in_progress\","
1805 " \"url\": \"ftp://example.com/example.txt\"}]"));
1778 } 1806 }
1779 1807
1780 // TODO(benjhayden): Set up a test ftp server, add ftp://localhost* to 1808 // TODO(benjhayden): Set up a test ftp server, add ftp://localhost* to
1781 // permissions, test downloading from ftp. 1809 // permissions, test downloading from ftp.
1782 1810
1783 // Valid URLs plus fragments are still valid URLs. 1811 // Valid URLs plus fragments are still valid URLs.
1784 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 1812 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
1785 DownloadExtensionTest_Download_URLFragment) { 1813 DownloadExtensionTest_Download_URLFragment) {
1786 LoadExtension("downloads_split"); 1814 LoadExtension("downloads_split");
1787 ASSERT_TRUE(StartEmbeddedTestServer()); 1815 ASSERT_TRUE(StartEmbeddedTestServer());
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
2026 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); 2054 DownloadItem* item = GetCurrentManager()->GetDownload(result_id);
2027 ASSERT_TRUE(item); 2055 ASSERT_TRUE(item);
2028 ScopedCancellingItem canceller(item); 2056 ScopedCancellingItem canceller(item);
2029 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); 2057 ASSERT_EQ(download_url, item->GetOriginalUrl().spec());
2030 2058
2031 ASSERT_TRUE(WaitForInterruption( 2059 ASSERT_TRUE(WaitForInterruption(
2032 item, 2060 item,
2033 content::DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED, 2061 content::DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED,
2034 base::StringPrintf("[{\"danger\": \"safe\"," 2062 base::StringPrintf("[{\"danger\": \"safe\","
2035 " \"incognito\": false," 2063 " \"incognito\": false,"
2036 " \"mime\": \"text/html\","
2037 " \"paused\": false," 2064 " \"paused\": false,"
2038 " \"url\": \"%s\"}]", 2065 " \"url\": \"%s\"}]",
2039 download_url.c_str()))); 2066 download_url.c_str())));
2040 } 2067 }
2041 2068
2042 // Test that DownloadsDownloadFunction propagates |headers| to the URLRequest. 2069 // Test that DownloadsDownloadFunction propagates |headers| to the URLRequest.
2043 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 2070 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
2044 DownloadExtensionTest_Download_Headers) { 2071 DownloadExtensionTest_Download_Headers) {
2045 LoadExtension("downloads_split"); 2072 LoadExtension("downloads_split");
2046 ASSERT_TRUE(StartEmbeddedTestServer()); 2073 ASSERT_TRUE(StartEmbeddedTestServer());
(...skipping 2104 matching lines...) Expand 10 before | Expand all | Expand 10 after
4151 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); 4178 EXPECT_EQ(downloads::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action);
4152 EXPECT_FALSE(warnings.empty()); 4179 EXPECT_FALSE(warnings.empty());
4153 EXPECT_EQ(Warning::kDownloadFilenameConflict, 4180 EXPECT_EQ(Warning::kDownloadFilenameConflict,
4154 warnings.begin()->warning_type()); 4181 warnings.begin()->warning_type());
4155 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); 4182 EXPECT_EQ("incumbent", warnings.begin()->extension_id());
4156 } 4183 }
4157 4184
4158 } // namespace extensions 4185 } // namespace extensions
4159 4186
4160 #endif // http://crbug.com/306144 4187 #endif // http://crbug.com/306144
OLDNEW
« no previous file with comments | « chrome/browser/download/download_target_determiner_unittest.cc ('k') | chrome/browser/extensions/webstore_installer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698