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

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: " Created 8 years, 8 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "content/test/test_file_error_injector.h" 61 #include "content/test/test_file_error_injector.h"
62 #include "content/test/test_navigation_observer.h" 62 #include "content/test/test_navigation_observer.h"
63 #include "net/base/net_util.h" 63 #include "net/base/net_util.h"
64 #include "net/test/test_server.h" 64 #include "net/test/test_server.h"
65 #include "testing/gtest/include/gtest/gtest.h" 65 #include "testing/gtest/include/gtest/gtest.h"
66 66
67 using content::BrowserThread; 67 using content::BrowserThread;
68 using content::DownloadItem; 68 using content::DownloadItem;
69 using content::DownloadManager; 69 using content::DownloadManager;
70 using content::DownloadPersistentStoreInfo; 70 using content::DownloadPersistentStoreInfo;
71 using content::DownloadUrlParameters;
71 using content::WebContents; 72 using content::WebContents;
72 73
73 namespace { 74 namespace {
74 75
75 // IDs and paths of CRX files used in tests. 76 // IDs and paths of CRX files used in tests.
76 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; 77 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
77 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); 78 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx"));
78 79
79 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; 80 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf";
80 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); 81 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx"));
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 667
667 if (download_info.download_method == DOWNLOAD_DIRECT) { 668 if (download_info.download_method == DOWNLOAD_DIRECT) {
668 // Go directly to download. Don't wait for navigation. 669 // Go directly to download. Don't wait for navigation.
669 content::DownloadSaveInfo save_info; 670 content::DownloadSaveInfo save_info;
670 // NOTE: |prompt_for_save_location| may change during the download. 671 // NOTE: |prompt_for_save_location| may change during the download.
671 save_info.prompt_for_save_location = false; 672 save_info.prompt_for_save_location = false;
672 673
673 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( 674 scoped_refptr<DownloadTestItemCreationObserver> creation_observer(
674 new DownloadTestItemCreationObserver); 675 new DownloadTestItemCreationObserver);
675 676
676 DownloadManagerForBrowser(browser())->DownloadUrl( 677 DownloadUrlParameters* params = DownloadUrlParameters::FromWebContents(
677 url, GURL(""), "", false, -1, save_info, web_contents, 678 web_contents, url, save_info);
678 creation_observer->callback()); 679 params->set_callback(creation_observer->callback());
680 DownloadManagerForBrowser(browser())->DownloadUrl(params);
679 681
680 // Wait until the item is created, or we have determined that it 682 // Wait until the item is created, or we have determined that it
681 // won't be. 683 // won't be.
682 creation_observer->WaitForDownloadItemCreation(); 684 creation_observer->WaitForDownloadItemCreation();
683 685
684 int32 invalid_id = content::DownloadId::Invalid().local(); 686 int32 invalid_id = content::DownloadId::Invalid().local();
685 EXPECT_EQ(download_info.show_download_item, 687 EXPECT_EQ(download_info.show_download_item,
686 creation_observer->succeeded()); 688 creation_observer->succeeded());
687 if (download_info.show_download_item) { 689 if (download_info.show_download_item) {
688 EXPECT_EQ(net::OK, creation_observer->error()); 690 EXPECT_EQ(net::OK, creation_observer->error());
(...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1967 ASSERT_TRUE(web_contents); 1969 ASSERT_TRUE(web_contents);
1968 1970
1969 DownloadTestObserver* observer( 1971 DownloadTestObserver* observer(
1970 new DownloadTestObserverTerminal( 1972 new DownloadTestObserverTerminal(
1971 DownloadManagerForBrowser(browser()), 1, 1973 DownloadManagerForBrowser(browser()), 1,
1972 false, // Ignore select file. 1974 false, // Ignore select file.
1973 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 1975 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1974 content::DownloadSaveInfo save_info; 1976 content::DownloadSaveInfo save_info;
1975 save_info.prompt_for_save_location = true; 1977 save_info.prompt_for_save_location = true;
1976 DownloadManagerForBrowser(browser())->DownloadUrl( 1978 DownloadManagerForBrowser(browser())->DownloadUrl(
1977 url, GURL(""), "", false, -1, save_info, web_contents, 1979 DownloadUrlParameters::FromWebContents(web_contents, url, save_info));
1978 DownloadManager::OnStartedCallback());
1979 observer->WaitForFinished(); 1980 observer->WaitForFinished();
1980 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1981 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1981 CheckDownloadStates(1, DownloadItem::COMPLETE); 1982 CheckDownloadStates(1, DownloadItem::COMPLETE);
1982 EXPECT_TRUE(observer->select_file_dialog_seen()); 1983 EXPECT_TRUE(observer->select_file_dialog_seen());
1983 1984
1984 // Check state. 1985 // Check state.
1985 EXPECT_EQ(1, browser()->tab_count()); 1986 EXPECT_EQ(1, browser()->tab_count());
1986 ASSERT_TRUE(CheckDownload(browser(), file, file)); 1987 ASSERT_TRUE(CheckDownload(browser(), file, file));
1987 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1988 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1988 } 1989 }
1989 1990
1990 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { 1991 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) {
1991 ASSERT_TRUE(InitialSetup(false)); 1992 ASSERT_TRUE(InitialSetup(false));
1992 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1993 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1993 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1994 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1994 1995
1995 WebContents* web_contents = browser()->GetSelectedWebContents(); 1996 WebContents* web_contents = browser()->GetSelectedWebContents();
1996 ASSERT_TRUE(web_contents); 1997 ASSERT_TRUE(web_contents);
1997 1998
1998 ScopedTempDir other_directory; 1999 ScopedTempDir other_directory;
1999 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); 2000 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
2000 FilePath target_file_full_path 2001 FilePath target_file_full_path
2001 = other_directory.path().Append(file.BaseName()); 2002 = other_directory.path().Append(file.BaseName());
2002 content::DownloadSaveInfo save_info; 2003 content::DownloadSaveInfo save_info;
2003 save_info.file_path = target_file_full_path; 2004 save_info.file_path = target_file_full_path;
2004 2005
2005 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); 2006 DownloadTestObserver* observer(CreateWaiter(browser(), 1));
2006 DownloadManagerForBrowser(browser())->DownloadUrl( 2007 DownloadManagerForBrowser(browser())->DownloadUrl(
2007 url, GURL(""), "", false, -1, save_info, web_contents, 2008 DownloadUrlParameters::FromWebContents(web_contents, url, save_info));
2008 DownloadManager::OnStartedCallback());
2009 observer->WaitForFinished(); 2009 observer->WaitForFinished();
2010 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2010 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2011 2011
2012 // Check state. 2012 // Check state.
2013 EXPECT_EQ(1, browser()->tab_count()); 2013 EXPECT_EQ(1, browser()->tab_count());
2014 ASSERT_TRUE(CheckDownloadFullPaths(browser(), 2014 ASSERT_TRUE(CheckDownloadFullPaths(browser(),
2015 target_file_full_path, 2015 target_file_full_path,
2016 OriginFile(file))); 2016 OriginFile(file)));
2017 2017
2018 // Temporary downloads won't be visible. 2018 // Temporary downloads won't be visible.
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
2476 ASSERT_TRUE(web_contents); 2476 ASSERT_TRUE(web_contents);
2477 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( 2477 scoped_refptr<DownloadTestItemCreationObserver> creation_observer(
2478 new DownloadTestItemCreationObserver); 2478 new DownloadTestItemCreationObserver);
2479 // Only for cleanup if a download is actually created. 2479 // Only for cleanup if a download is actually created.
2480 DownloadTestObserverTerminal backup_observer( 2480 DownloadTestObserverTerminal backup_observer(
2481 DownloadManagerForBrowser(browser()), 2481 DownloadManagerForBrowser(browser()),
2482 1, 2482 1,
2483 false, 2483 false,
2484 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); 2484 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
2485 2485
2486 DownloadManagerForBrowser(browser())->DownloadUrl( 2486 DownloadUrlParameters* params = DownloadUrlParameters::FromWebContents(
2487 url, GURL(), "", false, -1, content::DownloadSaveInfo(), 2487 web_contents, url, content::DownloadSaveInfo());
2488 web_contents, creation_observer->callback()); 2488 params->set_callback(creation_observer->callback());
2489 DownloadManagerForBrowser(browser())->DownloadUrl(params);
2489 2490
2490 creation_observer->WaitForDownloadItemCreation(); 2491 creation_observer->WaitForDownloadItemCreation();
2491 2492
2492 EXPECT_FALSE(creation_observer->succeeded()); 2493 EXPECT_FALSE(creation_observer->succeeded());
2493 EXPECT_EQ(net::ERR_DISALLOWED_URL_SCHEME, creation_observer->error()); 2494 EXPECT_EQ(net::ERR_DISALLOWED_URL_SCHEME, creation_observer->error());
2494 EXPECT_EQ(content::DownloadId::Invalid(), creation_observer->download_id()); 2495 EXPECT_EQ(content::DownloadId::Invalid(), creation_observer->download_id());
2495 downloads.clear(); 2496 downloads.clear();
2496 GetDownloads(browser(), &downloads); 2497 GetDownloads(browser(), &downloads);
2497 EXPECT_EQ(0u, downloads.size()); 2498 EXPECT_EQ(0u, downloads.size());
2498 2499
2499 if (creation_observer->succeeded()) { 2500 if (creation_observer->succeeded()) {
2500 // Wait until the download is done. We don't care how it's finished. 2501 // Wait until the download is done. We don't care how it's finished.
2501 backup_observer.WaitForFinished(); 2502 backup_observer.WaitForFinished();
2502 } 2503 }
2503 DownloadManagerForBrowser(browser())->RemoveAllDownloads(); 2504 DownloadManagerForBrowser(browser())->RemoveAllDownloads();
2504 } 2505 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_test_observer.h » ('j') | content/public/browser/download_manager.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698