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

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: fixes 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
« no previous file with comments | « no previous file | chrome/browser/download/download_test_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 662
661 if (download_info.download_method == DOWNLOAD_DIRECT) { 663 if (download_info.download_method == DOWNLOAD_DIRECT) {
662 // Go directly to download. Don't wait for navigation. 664 // Go directly to download. Don't wait for navigation.
663 content::DownloadSaveInfo save_info; 665 content::DownloadSaveInfo save_info;
664 // NOTE: |prompt_for_save_location| may change during the download. 666 // NOTE: |prompt_for_save_location| may change during the download.
665 save_info.prompt_for_save_location = false; 667 save_info.prompt_for_save_location = false;
666 668
667 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( 669 scoped_refptr<DownloadTestItemCreationObserver> creation_observer(
668 new DownloadTestItemCreationObserver); 670 new DownloadTestItemCreationObserver);
669 671
670 DownloadManagerForBrowser(browser())->DownloadUrl( 672 scoped_ptr<DownloadUrlParameters> params(
671 url, GURL(""), "", false, -1, save_info, web_contents, 673 DownloadUrlParameters::FromWebContents(web_contents, url, save_info));
672 creation_observer->callback()); 674 params->set_callback(creation_observer->callback());
675 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass());
673 676
674 // Wait until the item is created, or we have determined that it 677 // Wait until the item is created, or we have determined that it
675 // won't be. 678 // won't be.
676 creation_observer->WaitForDownloadItemCreation(); 679 creation_observer->WaitForDownloadItemCreation();
677 680
678 int32 invalid_id = content::DownloadId::Invalid().local(); 681 int32 invalid_id = content::DownloadId::Invalid().local();
679 EXPECT_EQ(download_info.show_download_item, 682 EXPECT_EQ(download_info.show_download_item,
680 creation_observer->succeeded()); 683 creation_observer->succeeded());
681 if (download_info.show_download_item) { 684 if (download_info.show_download_item) {
682 EXPECT_EQ(net::OK, creation_observer->error()); 685 EXPECT_EQ(net::OK, creation_observer->error());
(...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1928 WebContents* web_contents = browser()->GetSelectedWebContents(); 1931 WebContents* web_contents = browser()->GetSelectedWebContents();
1929 ASSERT_TRUE(web_contents); 1932 ASSERT_TRUE(web_contents);
1930 1933
1931 DownloadTestObserver* observer( 1934 DownloadTestObserver* observer(
1932 new DownloadTestObserverTerminal( 1935 new DownloadTestObserverTerminal(
1933 DownloadManagerForBrowser(browser()), 1, 1936 DownloadManagerForBrowser(browser()), 1,
1934 false, // Ignore select file. 1937 false, // Ignore select file.
1935 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 1938 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1936 content::DownloadSaveInfo save_info; 1939 content::DownloadSaveInfo save_info;
1937 save_info.prompt_for_save_location = true; 1940 save_info.prompt_for_save_location = true;
1938 DownloadManagerForBrowser(browser())->DownloadUrl( 1941 scoped_ptr<DownloadUrlParameters> params(
1939 url, GURL(""), "", false, -1, save_info, web_contents, 1942 DownloadUrlParameters::FromWebContents(web_contents, url, save_info));
1940 DownloadManager::OnStartedCallback()); 1943 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass());
1941 observer->WaitForFinished(); 1944 observer->WaitForFinished();
1942 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1945 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1943 CheckDownloadStates(1, DownloadItem::COMPLETE); 1946 CheckDownloadStates(1, DownloadItem::COMPLETE);
1944 EXPECT_TRUE(observer->select_file_dialog_seen()); 1947 EXPECT_TRUE(observer->select_file_dialog_seen());
1945 1948
1946 // Check state. 1949 // Check state.
1947 EXPECT_EQ(1, browser()->tab_count()); 1950 EXPECT_EQ(1, browser()->tab_count());
1948 ASSERT_TRUE(CheckDownload(browser(), file, file)); 1951 ASSERT_TRUE(CheckDownload(browser(), file, file));
1949 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1952 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1950 } 1953 }
1951 1954
1952 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { 1955 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) {
1953 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1956 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1954 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1957 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1955 1958
1956 WebContents* web_contents = browser()->GetSelectedWebContents(); 1959 WebContents* web_contents = browser()->GetSelectedWebContents();
1957 ASSERT_TRUE(web_contents); 1960 ASSERT_TRUE(web_contents);
1958 1961
1959 ScopedTempDir other_directory; 1962 ScopedTempDir other_directory;
1960 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); 1963 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
1961 FilePath target_file_full_path 1964 FilePath target_file_full_path
1962 = other_directory.path().Append(file.BaseName()); 1965 = other_directory.path().Append(file.BaseName());
1963 content::DownloadSaveInfo save_info; 1966 content::DownloadSaveInfo save_info;
1964 save_info.file_path = target_file_full_path; 1967 save_info.file_path = target_file_full_path;
1965 1968
1966 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); 1969 DownloadTestObserver* observer(CreateWaiter(browser(), 1));
1967 DownloadManagerForBrowser(browser())->DownloadUrl( 1970 scoped_ptr<DownloadUrlParameters> params(
1968 url, GURL(""), "", false, -1, save_info, web_contents, 1971 DownloadUrlParameters::FromWebContents(web_contents, url, save_info));
1969 DownloadManager::OnStartedCallback()); 1972 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass());
1970 observer->WaitForFinished(); 1973 observer->WaitForFinished();
1971 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1974 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1972 1975
1973 // Check state. 1976 // Check state.
1974 EXPECT_EQ(1, browser()->tab_count()); 1977 EXPECT_EQ(1, browser()->tab_count());
1975 ASSERT_TRUE(CheckDownloadFullPaths(browser(), 1978 ASSERT_TRUE(CheckDownloadFullPaths(browser(),
1976 target_file_full_path, 1979 target_file_full_path,
1977 OriginFile(file))); 1980 OriginFile(file)));
1978 1981
1979 // Temporary downloads won't be visible. 1982 // Temporary downloads won't be visible.
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
2391 GURL url(test_server()->GetURL(path)); 2394 GURL url(test_server()->GetURL(path));
2392 2395
2393 DownloadTestObserver* observer(DangerousDownloadWaiter( 2396 DownloadTestObserver* observer(DangerousDownloadWaiter(
2394 browser(), 1, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); 2397 browser(), 1, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
2395 ui_test_utils::NavigateToURL(browser(), url); 2398 ui_test_utils::NavigateToURL(browser(), url);
2396 observer->WaitForFinished(); 2399 observer->WaitForFinished();
2397 2400
2398 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2401 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2399 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 2402 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
2400 } 2403 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_test_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698