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

Side by Side Diff: chrome/browser/download/download_browsertest.cc

Issue 10232010: DownloadUrlParameters (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: cleaning Created 8 years, 7 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 <sstream> 5 #include <sstream>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 30 matching lines...) Expand all
41 #include "chrome/common/chrome_notification_types.h" 41 #include "chrome/common/chrome_notification_types.h"
42 #include "chrome/common/chrome_paths.h" 42 #include "chrome/common/chrome_paths.h"
43 #include "chrome/common/pref_names.h" 43 #include "chrome/common/pref_names.h"
44 #include "chrome/common/url_constants.h" 44 #include "chrome/common/url_constants.h"
45 #include "chrome/test/base/in_process_browser_test.h" 45 #include "chrome/test/base/in_process_browser_test.h"
46 #include "chrome/test/base/ui_test_utils.h" 46 #include "chrome/test/base/ui_test_utils.h"
47 #include "content/public/browser/download_item.h" 47 #include "content/public/browser/download_item.h"
48 #include "content/public/browser/download_manager.h" 48 #include "content/public/browser/download_manager.h"
49 #include "content/public/browser/download_persistent_store_info.h" 49 #include "content/public/browser/download_persistent_store_info.h"
50 #include "content/public/browser/download_save_info.h" 50 #include "content/public/browser/download_save_info.h"
51 #include "content/public/browser/download_url_parameters.h"
51 #include "content/public/browser/notification_source.h" 52 #include "content/public/browser/notification_source.h"
52 #include "content/public/browser/render_view_host.h" 53 #include "content/public/browser/render_view_host.h"
53 #include "content/public/browser/resource_context.h" 54 #include "content/public/browser/resource_context.h"
54 #include "content/public/browser/web_contents.h" 55 #include "content/public/browser/web_contents.h"
55 #include "content/public/common/context_menu_params.h" 56 #include "content/public/common/context_menu_params.h"
56 #include "content/public/common/page_transition_types.h" 57 #include "content/public/common/page_transition_types.h"
57 #include "content/test/net/url_request_mock_http_job.h" 58 #include "content/test/net/url_request_mock_http_job.h"
58 #include "content/test/net/url_request_slow_download_job.h" 59 #include "content/test/net/url_request_slow_download_job.h"
59 #include "content/test/test_file_error_injector.h" 60 #include "content/test/test_file_error_injector.h"
60 #include "content/test/test_navigation_observer.h" 61 #include "content/test/test_navigation_observer.h"
61 #include "net/base/net_util.h" 62 #include "net/base/net_util.h"
62 #include "net/test/test_server.h" 63 #include "net/test/test_server.h"
63 #include "testing/gtest/include/gtest/gtest.h" 64 #include "testing/gtest/include/gtest/gtest.h"
64 65
65 using content::BrowserThread; 66 using content::BrowserThread;
66 using content::DownloadItem; 67 using content::DownloadItem;
67 using content::DownloadManager; 68 using content::DownloadManager;
68 using content::DownloadPersistentStoreInfo; 69 using content::DownloadPersistentStoreInfo;
70 using content::DownloadUrlParameters;
69 using content::WebContents; 71 using content::WebContents;
70 72
71 namespace { 73 namespace {
72 74
73 // IDs and paths of CRX files used in tests. 75 // IDs and paths of CRX files used in tests.
74 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; 76 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
75 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); 77 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx"));
76 78
77 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; 79 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf";
78 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); 80 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx"));
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 661
660 if (download_info.download_method == DOWNLOAD_DIRECT) { 662 if (download_info.download_method == DOWNLOAD_DIRECT) {
661 // Go directly to download. Don't wait for navigation. 663 // Go directly to download. Don't wait for navigation.
662 content::DownloadSaveInfo save_info; 664 content::DownloadSaveInfo save_info;
663 // NOTE: |prompt_for_save_location| may change during the download. 665 // NOTE: |prompt_for_save_location| may change during the download.
664 save_info.prompt_for_save_location = false; 666 save_info.prompt_for_save_location = false;
665 667
666 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( 668 scoped_refptr<DownloadTestItemCreationObserver> creation_observer(
667 new DownloadTestItemCreationObserver); 669 new DownloadTestItemCreationObserver);
668 670
669 DownloadManagerForBrowser(browser())->DownloadUrl( 671 scoped_ptr<DownloadUrlParameters> params(
670 url, GURL(""), "", false, -1, save_info, web_contents, 672 DownloadUrlParameters::FromWebContents(web_contents, url, save_info));
671 creation_observer->callback()); 673 params->set_callback(creation_observer->callback());
674 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass());
672 675
673 // Wait until the item is created, or we have determined that it 676 // Wait until the item is created, or we have determined that it
674 // won't be. 677 // won't be.
675 creation_observer->WaitForDownloadItemCreation(); 678 creation_observer->WaitForDownloadItemCreation();
676 679
677 int32 invalid_id = content::DownloadId::Invalid().local(); 680 int32 invalid_id = content::DownloadId::Invalid().local();
678 EXPECT_EQ(download_info.show_download_item, 681 EXPECT_EQ(download_info.show_download_item,
679 creation_observer->succeeded()); 682 creation_observer->succeeded());
680 if (download_info.show_download_item) { 683 if (download_info.show_download_item) {
681 EXPECT_EQ(net::OK, creation_observer->error()); 684 EXPECT_EQ(net::OK, creation_observer->error());
(...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 WebContents* web_contents = browser()->GetSelectedWebContents(); 1930 WebContents* web_contents = browser()->GetSelectedWebContents();
1928 ASSERT_TRUE(web_contents); 1931 ASSERT_TRUE(web_contents);
1929 1932
1930 DownloadTestObserver* observer( 1933 DownloadTestObserver* observer(
1931 new DownloadTestObserverTerminal( 1934 new DownloadTestObserverTerminal(
1932 DownloadManagerForBrowser(browser()), 1, 1935 DownloadManagerForBrowser(browser()), 1,
1933 false, // Ignore select file. 1936 false, // Ignore select file.
1934 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 1937 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1935 content::DownloadSaveInfo save_info; 1938 content::DownloadSaveInfo save_info;
1936 save_info.prompt_for_save_location = true; 1939 save_info.prompt_for_save_location = true;
1937 DownloadManagerForBrowser(browser())->DownloadUrl( 1940 scoped_ptr<DownloadUrlParameters> params(
1938 url, GURL(""), "", false, -1, save_info, web_contents, 1941 DownloadUrlParameters::FromWebContents(web_contents, url, save_info));
1939 DownloadManager::OnStartedCallback()); 1942 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass());
1940 observer->WaitForFinished(); 1943 observer->WaitForFinished();
1941 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1944 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1942 CheckDownloadStates(1, DownloadItem::COMPLETE); 1945 CheckDownloadStates(1, DownloadItem::COMPLETE);
1943 EXPECT_TRUE(observer->select_file_dialog_seen()); 1946 EXPECT_TRUE(observer->select_file_dialog_seen());
1944 1947
1945 // Check state. 1948 // Check state.
1946 EXPECT_EQ(1, browser()->tab_count()); 1949 EXPECT_EQ(1, browser()->tab_count());
1947 ASSERT_TRUE(CheckDownload(browser(), file, file)); 1950 ASSERT_TRUE(CheckDownload(browser(), file, file));
1948 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1951 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1949 } 1952 }
1950 1953
1951 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { 1954 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) {
1952 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1955 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1953 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1956 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1954 1957
1955 WebContents* web_contents = browser()->GetSelectedWebContents(); 1958 WebContents* web_contents = browser()->GetSelectedWebContents();
1956 ASSERT_TRUE(web_contents); 1959 ASSERT_TRUE(web_contents);
1957 1960
1958 ScopedTempDir other_directory; 1961 ScopedTempDir other_directory;
1959 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); 1962 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
1960 FilePath target_file_full_path 1963 FilePath target_file_full_path
1961 = other_directory.path().Append(file.BaseName()); 1964 = other_directory.path().Append(file.BaseName());
1962 content::DownloadSaveInfo save_info; 1965 content::DownloadSaveInfo save_info;
1963 save_info.file_path = target_file_full_path; 1966 save_info.file_path = target_file_full_path;
1964 1967
1965 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); 1968 DownloadTestObserver* observer(CreateWaiter(browser(), 1));
1966 DownloadManagerForBrowser(browser())->DownloadUrl( 1969 scoped_ptr<DownloadUrlParameters> params(
1967 url, GURL(""), "", false, -1, save_info, web_contents, 1970 DownloadUrlParameters::FromWebContents(web_contents, url, save_info));
1968 DownloadManager::OnStartedCallback()); 1971 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass());
1969 observer->WaitForFinished(); 1972 observer->WaitForFinished();
1970 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1973 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1971 1974
1972 // Check state. 1975 // Check state.
1973 EXPECT_EQ(1, browser()->tab_count()); 1976 EXPECT_EQ(1, browser()->tab_count());
1974 ASSERT_TRUE(CheckDownloadFullPaths(browser(), 1977 ASSERT_TRUE(CheckDownloadFullPaths(browser(),
1975 target_file_full_path, 1978 target_file_full_path,
1976 OriginFile(file))); 1979 OriginFile(file)));
1977 1980
1978 // Temporary downloads won't be visible. 1981 // Temporary downloads won't be visible.
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
2390 GURL url(test_server()->GetURL(path)); 2393 GURL url(test_server()->GetURL(path));
2391 2394
2392 DownloadTestObserver* observer(DangerousDownloadWaiter( 2395 DownloadTestObserver* observer(DangerousDownloadWaiter(
2393 browser(), 1, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 2396 browser(), 1, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
2394 ui_test_utils::NavigateToURL(browser(), url); 2397 ui_test_utils::NavigateToURL(browser(), url);
2395 observer->WaitForFinished(); 2398 observer->WaitForFinished();
2396 2399
2397 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2400 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2398 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 2401 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
2399 } 2402 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_test_observer.h » ('j') | content/browser/download/download_manager_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698