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

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

Issue 11050003: Shift EnsureNoPendingDownloads() implementation into tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 DVLOG(1) << " " << __FUNCTION__ << "()" 806 DVLOG(1) << " " << __FUNCTION__ << "()"
807 << " folder = '" << destination_folder.value() << "'"; 807 << " folder = '" << destination_folder.value() << "'";
808 file_util::PermissionRestorer permission_restorer(destination_folder); 808 file_util::PermissionRestorer permission_restorer(destination_folder);
809 EXPECT_TRUE(file_util::MakeFileUnwritable(destination_folder)); 809 EXPECT_TRUE(file_util::MakeFileUnwritable(destination_folder));
810 810
811 for (size_t i = 0; i < count; ++i) { 811 for (size_t i = 0; i < count; ++i) {
812 DownloadFilesCheckErrorsLoopBody(download_info[i], i); 812 DownloadFilesCheckErrorsLoopBody(download_info[i], i);
813 } 813 }
814 } 814 }
815 815
816 bool EnsureNoPendingDownloads() {
817 bool result = true;
818 BrowserThread::PostTask(
819 BrowserThread::IO, FROM_HERE,
820 base::Bind(&EnsureNoPendingDownloadJobsOnIO, &result));
821 MessageLoop::current()->Run();
822 return result && DownloadManager::EnsureNoPendingDownloadsForTesting();
823 }
824
825 // A mock install prompt that simulates the user allowing an install request. 816 // A mock install prompt that simulates the user allowing an install request.
826 void SetAllowMockInstallPrompt() { 817 void SetAllowMockInstallPrompt() {
827 gfx::NativeWindow parent = 818 gfx::NativeWindow parent =
828 browser()->window() ? browser()->window()->GetNativeWindow() : NULL; 819 browser()->window() ? browser()->window()->GetNativeWindow() : NULL;
829 download_crx_util::SetMockInstallPromptForTesting( 820 download_crx_util::SetMockInstallPromptForTesting(
830 new MockAutoConfirmExtensionInstallPrompt(parent, 821 new MockAutoConfirmExtensionInstallPrompt(parent,
831 browser(), 822 browser(),
832 browser()->profile())); 823 browser()->profile()));
833 } 824 }
834 825
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 // download never makes it to the downloads system. 972 // download never makes it to the downloads system.
982 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadResourceThrottleCancels) { 973 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadResourceThrottleCancels) {
983 // Navigate to a page with the same domain as the file to download. We can't 974 // Navigate to a page with the same domain as the file to download. We can't
984 // navigate directly to the file we don't want to download because cross-site 975 // navigate directly to the file we don't want to download because cross-site
985 // navigations reset the TabDownloadState. 976 // navigations reset the TabDownloadState.
986 FilePath same_site_path(FILE_PATH_LITERAL("download_script.html")); 977 FilePath same_site_path(FILE_PATH_LITERAL("download_script.html"));
987 GURL same_site_url(URLRequestMockHTTPJob::GetMockUrl(same_site_path)); 978 GURL same_site_url(URLRequestMockHTTPJob::GetMockUrl(same_site_path));
988 ui_test_utils::NavigateToURL(browser(), same_site_url); 979 ui_test_utils::NavigateToURL(browser(), same_site_url);
989 980
990 // Make sure the initial navigation didn't trigger a download. 981 // Make sure the initial navigation didn't trigger a download.
991 EXPECT_TRUE(EnsureNoPendingDownloads()); 982 std::vector<content::DownloadItem*> items;
983 DownloadManagerForBrowser(browser())->GetAllDownloads(&items);
984 EXPECT_EQ(0u, items.size());
992 985
993 // Disable downloads for the tab. 986 // Disable downloads for the tab.
994 WebContents* web_contents = chrome::GetActiveWebContents(browser()); 987 WebContents* web_contents = chrome::GetActiveWebContents(browser());
995 DownloadRequestLimiter::TabDownloadState* tab_download_state = 988 DownloadRequestLimiter::TabDownloadState* tab_download_state =
996 g_browser_process->download_request_limiter()->GetDownloadState( 989 g_browser_process->download_request_limiter()->GetDownloadState(
997 web_contents, web_contents, true); 990 web_contents, web_contents, true);
998 ASSERT_TRUE(tab_download_state); 991 ASSERT_TRUE(tab_download_state);
999 tab_download_state->set_download_status( 992 tab_download_state->set_download_status(
1000 DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED); 993 DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED);
1001 994
(...skipping 18 matching lines...) Expand all
1020 1013
1021 // Check that we did not download the file. 1014 // Check that we did not download the file.
1022 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1015 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1023 FilePath file_path(DestinationFile(browser(), file)); 1016 FilePath file_path(DestinationFile(browser(), file));
1024 EXPECT_FALSE(file_util::PathExists(file_path)); 1017 EXPECT_FALSE(file_util::PathExists(file_path));
1025 1018
1026 // Check state. 1019 // Check state.
1027 EXPECT_EQ(1, browser()->tab_count()); 1020 EXPECT_EQ(1, browser()->tab_count());
1028 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1021 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1029 1022
1030 // Verify that there's no pending download. 1023 // Verify that there's no pending download. The resource throttle
1031 EXPECT_TRUE(EnsureNoPendingDownloads()); 1024 // should have deleted it before it created a download item, so it
1025 // shouldn't be available as a cancelled download either.
1026 DownloadManagerForBrowser(browser())->GetAllDownloads(&items);
1027 EXPECT_EQ(0u, items.size());
1032 } 1028 }
1033 1029
1034 // Download a 0-size file with a content-disposition header, verify that the 1030 // Download a 0-size file with a content-disposition header, verify that the
1035 // download tab opened and the file exists as the filename specified in the 1031 // download tab opened and the file exists as the filename specified in the
1036 // header. This also ensures we properly handle empty file downloads. 1032 // header. This also ensures we properly handle empty file downloads.
1037 // The download shelf should be visible in the current tab. 1033 // The download shelf should be visible in the current tab.
1038 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { 1034 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) {
1039 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); 1035 FilePath file(FILE_PATH_LITERAL("download-test3.gif"));
1040 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1036 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1041 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); 1037 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif"));
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after
2235 GetDownloads(browser(), &download_items); 2231 GetDownloads(browser(), &download_items);
2236 ASSERT_EQ(1u, download_items.size()); 2232 ASSERT_EQ(1u, download_items.size());
2237 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), 2233 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"),
2238 download_items[0]->GetOriginalUrl()); 2234 download_items[0]->GetOriginalUrl());
2239 2235
2240 // Check that the file contains the expected referrer. 2236 // Check that the file contains the expected referrer.
2241 FilePath file(download_items[0]->GetFullPath()); 2237 FilePath file(download_items[0]->GetFullPath());
2242 std::string expected_contents = test_server()->GetURL("").spec(); 2238 std::string expected_contents = test_server()->GetURL("").spec();
2243 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); 2239 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length()));
2244 } 2240 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/download/download_browsertest.cc » ('j') | content/browser/download/download_browsertest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698