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

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

Issue 819133004: Make callers of CommandLine use it via the base:: namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 5 years, 12 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
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/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 ASSERT_TRUE(InitialSetup()); 447 ASSERT_TRUE(InitialSetup());
448 } 448 }
449 449
450 void TearDownOnMainThread() override { 450 void TearDownOnMainThread() override {
451 // Needs to be torn down on the main thread. file_activity_observer_ holds a 451 // Needs to be torn down on the main thread. file_activity_observer_ holds a
452 // reference to the ChromeDownloadManagerDelegate which should be destroyed 452 // reference to the ChromeDownloadManagerDelegate which should be destroyed
453 // on the UI thread. 453 // on the UI thread.
454 file_activity_observer_.reset(); 454 file_activity_observer_.reset();
455 } 455 }
456 456
457 void SetUpCommandLine(CommandLine* command_line) override { 457 void SetUpCommandLine(base::CommandLine* command_line) override {
458 command_line->AppendSwitch(switches::kDisablePluginsDiscovery); 458 command_line->AppendSwitch(switches::kDisablePluginsDiscovery);
459 } 459 }
460 460
461 // Returning false indicates a failure of the setup, and should be asserted 461 // Returning false indicates a failure of the setup, and should be asserted
462 // in the caller. 462 // in the caller.
463 virtual bool InitialSetup() { 463 virtual bool InitialSetup() {
464 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_); 464 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_);
465 EXPECT_TRUE(have_test_dir); 465 EXPECT_TRUE(have_test_dir);
466 if (!have_test_dir) 466 if (!have_test_dir)
467 return false; 467 return false;
(...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 EXPECT_EQ(content::DownloadItem::INTERRUPTED, row1.state); 1817 EXPECT_EQ(content::DownloadItem::INTERRUPTED, row1.state);
1818 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, 1818 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED,
1819 row1.interrupt_reason); 1819 row1.interrupt_reason);
1820 EXPECT_FALSE(row1.opened); 1820 EXPECT_FALSE(row1.opened);
1821 } 1821 }
1822 1822
1823 // Make sure a dangerous file shows up properly in the history. 1823 // Make sure a dangerous file shows up properly in the history.
1824 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryDangerCheck) { 1824 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryDangerCheck) {
1825 #if defined(OS_WIN) && defined(USE_ASH) 1825 #if defined(OS_WIN) && defined(USE_ASH)
1826 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 1826 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
1827 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 1827 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1828 switches::kAshBrowserTests))
1828 return; 1829 return;
1829 #endif 1830 #endif
1830 1831
1831 // .swf file so that it's dangerous on all platforms (including CrOS). 1832 // .swf file so that it's dangerous on all platforms (including CrOS).
1832 base::FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf")); 1833 base::FilePath file(FILE_PATH_LITERAL("downloads/dangerous/dangerous.swf"));
1833 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); 1834 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file));
1834 1835
1835 // Download the url and wait until the object has been stored. 1836 // Download the url and wait until the object has been stored.
1836 scoped_ptr<content::DownloadTestObserver> download_observer( 1837 scoped_ptr<content::DownloadTestObserver> download_observer(
1837 new content::DownloadTestObserverTerminal( 1838 new content::DownloadTestObserverTerminal(
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
2871 observer->WaitForFinished(); 2872 observer->WaitForFinished();
2872 2873
2873 // Verify that download shelf is not shown. 2874 // Verify that download shelf is not shown.
2874 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 2875 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
2875 } 2876 }
2876 2877
2877 // Verify the multiple downloads infobar. 2878 // Verify the multiple downloads infobar.
2878 IN_PROC_BROWSER_TEST_F(DownloadTest, TestMultipleDownloadsInfobar) { 2879 IN_PROC_BROWSER_TEST_F(DownloadTest, TestMultipleDownloadsInfobar) {
2879 #if defined(OS_WIN) && defined(USE_ASH) 2880 #if defined(OS_WIN) && defined(USE_ASH)
2880 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 2881 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
2881 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 2882 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2883 switches::kAshBrowserTests))
2882 return; 2884 return;
2883 #endif 2885 #endif
2884 2886
2885 ASSERT_TRUE(test_server()->Start()); 2887 ASSERT_TRUE(test_server()->Start());
2886 2888
2887 // Create a downloads observer. 2889 // Create a downloads observer.
2888 scoped_ptr<content::DownloadTestObserver> downloads_observer( 2890 scoped_ptr<content::DownloadTestObserver> downloads_observer(
2889 CreateWaiter(browser(), 2)); 2891 CreateWaiter(browser(), 2));
2890 2892
2891 // Create an infobar observer. 2893 // Create an infobar observer.
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
3162 EXPECT_EQ(dir.AppendASCII("off").value(), off_prefs->SaveFilePath().value()); 3164 EXPECT_EQ(dir.AppendASCII("off").value(), off_prefs->SaveFilePath().value());
3163 3165
3164 on_prefs->SetSaveFilePath(dir.AppendASCII("on")); 3166 on_prefs->SetSaveFilePath(dir.AppendASCII("on"));
3165 EXPECT_EQ(dir.AppendASCII("on").value(), on_prefs->SaveFilePath().value()); 3167 EXPECT_EQ(dir.AppendASCII("on").value(), on_prefs->SaveFilePath().value());
3166 EXPECT_EQ(dir.AppendASCII("off").value(), off_prefs->SaveFilePath().value()); 3168 EXPECT_EQ(dir.AppendASCII("off").value(), off_prefs->SaveFilePath().value());
3167 } 3169 }
3168 3170
3169 // A download that is interrupted due to a file error should be able to be 3171 // A download that is interrupted due to a file error should be able to be
3170 // resumed. 3172 // resumed.
3171 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_NoPrompt) { 3173 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_NoPrompt) {
3172 CommandLine::ForCurrentProcess()->AppendSwitch( 3174 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3173 switches::kEnableDownloadResumption); 3175 switches::kEnableDownloadResumption);
3174 scoped_refptr<content::TestFileErrorInjector> error_injector( 3176 scoped_refptr<content::TestFileErrorInjector> error_injector(
3175 content::TestFileErrorInjector::Create( 3177 content::TestFileErrorInjector::Create(
3176 DownloadManagerForBrowser(browser()))); 3178 DownloadManagerForBrowser(browser())));
3177 scoped_ptr<content::DownloadTestObserver> completion_observer( 3179 scoped_ptr<content::DownloadTestObserver> completion_observer(
3178 CreateWaiter(browser(), 1)); 3180 CreateWaiter(browser(), 1));
3179 EnableFileChooser(true); 3181 EnableFileChooser(true);
3180 3182
3181 DownloadItem* download = StartMockDownloadAndInjectError( 3183 DownloadItem* download = StartMockDownloadAndInjectError(
3182 error_injector.get(), content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); 3184 error_injector.get(), content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED);
3183 ASSERT_TRUE(download); 3185 ASSERT_TRUE(download);
3184 3186
3185 download->Resume(); 3187 download->Resume();
3186 completion_observer->WaitForFinished(); 3188 completion_observer->WaitForFinished();
3187 3189
3188 EXPECT_EQ( 3190 EXPECT_EQ(
3189 1u, completion_observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 3191 1u, completion_observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
3190 EXPECT_FALSE(DidShowFileChooser()); 3192 EXPECT_FALSE(DidShowFileChooser());
3191 } 3193 }
3192 3194
3193 // A download that's interrupted due to a reason that indicates that the target 3195 // A download that's interrupted due to a reason that indicates that the target
3194 // path is invalid or unusable should cause a prompt to be displayed on 3196 // path is invalid or unusable should cause a prompt to be displayed on
3195 // resumption. 3197 // resumption.
3196 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_WithPrompt) { 3198 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_WithPrompt) {
3197 CommandLine::ForCurrentProcess()->AppendSwitch( 3199 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3198 switches::kEnableDownloadResumption); 3200 switches::kEnableDownloadResumption);
3199 scoped_refptr<content::TestFileErrorInjector> error_injector( 3201 scoped_refptr<content::TestFileErrorInjector> error_injector(
3200 content::TestFileErrorInjector::Create( 3202 content::TestFileErrorInjector::Create(
3201 DownloadManagerForBrowser(browser()))); 3203 DownloadManagerForBrowser(browser())));
3202 scoped_ptr<content::DownloadTestObserver> completion_observer( 3204 scoped_ptr<content::DownloadTestObserver> completion_observer(
3203 CreateWaiter(browser(), 1)); 3205 CreateWaiter(browser(), 1));
3204 EnableFileChooser(true); 3206 EnableFileChooser(true);
3205 3207
3206 DownloadItem* download = StartMockDownloadAndInjectError( 3208 DownloadItem* download = StartMockDownloadAndInjectError(
3207 error_injector.get(), content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE); 3209 error_injector.get(), content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE);
3208 ASSERT_TRUE(download); 3210 ASSERT_TRUE(download);
3209 3211
3210 download->Resume(); 3212 download->Resume();
3211 completion_observer->WaitForFinished(); 3213 completion_observer->WaitForFinished();
3212 3214
3213 EXPECT_EQ( 3215 EXPECT_EQ(
3214 1u, completion_observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 3216 1u, completion_observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
3215 EXPECT_TRUE(DidShowFileChooser()); 3217 EXPECT_TRUE(DidShowFileChooser());
3216 } 3218 }
3217 3219
3218 // The user shouldn't be prompted on a resumed download unless a prompt is 3220 // The user shouldn't be prompted on a resumed download unless a prompt is
3219 // necessary due to the interrupt reason. 3221 // necessary due to the interrupt reason.
3220 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_WithPromptAlways) { 3222 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_WithPromptAlways) {
3221 CommandLine::ForCurrentProcess()->AppendSwitch( 3223 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3222 switches::kEnableDownloadResumption); 3224 switches::kEnableDownloadResumption);
3223 browser()->profile()->GetPrefs()->SetBoolean( 3225 browser()->profile()->GetPrefs()->SetBoolean(
3224 prefs::kPromptForDownload, true); 3226 prefs::kPromptForDownload, true);
3225 scoped_refptr<content::TestFileErrorInjector> error_injector( 3227 scoped_refptr<content::TestFileErrorInjector> error_injector(
3226 content::TestFileErrorInjector::Create( 3228 content::TestFileErrorInjector::Create(
3227 DownloadManagerForBrowser(browser()))); 3229 DownloadManagerForBrowser(browser())));
3228 scoped_ptr<content::DownloadTestObserver> completion_observer( 3230 scoped_ptr<content::DownloadTestObserver> completion_observer(
3229 CreateWaiter(browser(), 1)); 3231 CreateWaiter(browser(), 1));
3230 EnableFileChooser(true); 3232 EnableFileChooser(true);
3231 3233
3232 DownloadItem* download = StartMockDownloadAndInjectError( 3234 DownloadItem* download = StartMockDownloadAndInjectError(
3233 error_injector.get(), content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); 3235 error_injector.get(), content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED);
3234 ASSERT_TRUE(download); 3236 ASSERT_TRUE(download);
3235 3237
3236 // Prompts the user initially because of the kPromptForDownload preference. 3238 // Prompts the user initially because of the kPromptForDownload preference.
3237 EXPECT_TRUE(DidShowFileChooser()); 3239 EXPECT_TRUE(DidShowFileChooser());
3238 3240
3239 download->Resume(); 3241 download->Resume();
3240 completion_observer->WaitForFinished(); 3242 completion_observer->WaitForFinished();
3241 3243
3242 EXPECT_EQ( 3244 EXPECT_EQ(
3243 1u, completion_observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 3245 1u, completion_observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
3244 // Shouldn't prompt for resumption. 3246 // Shouldn't prompt for resumption.
3245 EXPECT_FALSE(DidShowFileChooser()); 3247 EXPECT_FALSE(DidShowFileChooser());
3246 } 3248 }
3247 3249
3248 // A download that is interrupted due to a transient error should be resumed 3250 // A download that is interrupted due to a transient error should be resumed
3249 // automatically. 3251 // automatically.
3250 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_Automatic) { 3252 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_Automatic) {
3251 CommandLine::ForCurrentProcess()->AppendSwitch( 3253 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3252 switches::kEnableDownloadResumption); 3254 switches::kEnableDownloadResumption);
3253 scoped_refptr<content::TestFileErrorInjector> error_injector( 3255 scoped_refptr<content::TestFileErrorInjector> error_injector(
3254 content::TestFileErrorInjector::Create( 3256 content::TestFileErrorInjector::Create(
3255 DownloadManagerForBrowser(browser()))); 3257 DownloadManagerForBrowser(browser())));
3256 3258
3257 DownloadItem* download = StartMockDownloadAndInjectError( 3259 DownloadItem* download = StartMockDownloadAndInjectError(
3258 error_injector.get(), 3260 error_injector.get(),
3259 content::DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR); 3261 content::DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR);
3260 ASSERT_TRUE(download); 3262 ASSERT_TRUE(download);
3261 3263
3262 // The number of times this the download is resumed automatically is defined 3264 // The number of times this the download is resumed automatically is defined
3263 // in DownloadItemImpl::kMaxAutoResumeAttempts. The number of DownloadFiles 3265 // in DownloadItemImpl::kMaxAutoResumeAttempts. The number of DownloadFiles
3264 // created should be that number + 1 (for the original download request). We 3266 // created should be that number + 1 (for the original download request). We
3265 // only care that it is greater than 1. 3267 // only care that it is greater than 1.
3266 EXPECT_GT(1u, error_injector->TotalFileCount()); 3268 EXPECT_GT(1u, error_injector->TotalFileCount());
3267 } 3269 }
3268 3270
3269 // An interrupting download should be resumable multiple times. 3271 // An interrupting download should be resumable multiple times.
3270 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_MultipleAttempts) { 3272 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_MultipleAttempts) {
3271 CommandLine::ForCurrentProcess()->AppendSwitch( 3273 base::CommandLine::ForCurrentProcess()->AppendSwitch(
3272 switches::kEnableDownloadResumption); 3274 switches::kEnableDownloadResumption);
3273 scoped_refptr<content::TestFileErrorInjector> error_injector( 3275 scoped_refptr<content::TestFileErrorInjector> error_injector(
3274 content::TestFileErrorInjector::Create( 3276 content::TestFileErrorInjector::Create(
3275 DownloadManagerForBrowser(browser()))); 3277 DownloadManagerForBrowser(browser())));
3276 scoped_ptr<DownloadTestObserverNotInProgress> completion_observer( 3278 scoped_ptr<DownloadTestObserverNotInProgress> completion_observer(
3277 new DownloadTestObserverNotInProgress( 3279 new DownloadTestObserverNotInProgress(
3278 DownloadManagerForBrowser(browser()), 1)); 3280 DownloadManagerForBrowser(browser()), 1));
3279 // Wait for two transitions to a resumable state 3281 // Wait for two transitions to a resumable state
3280 scoped_ptr<content::DownloadTestObserver> resumable_observer( 3282 scoped_ptr<content::DownloadTestObserver> resumable_observer(
3281 new DownloadTestObserverResumable( 3283 new DownloadTestObserverResumable(
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
3511 *(downloads[0]))); 3513 *(downloads[0])));
3512 3514
3513 // Begin feedback and check that the file is "stolen". 3515 // Begin feedback and check that the file is "stolen".
3514 download_protection_service->feedback_service()->BeginFeedbackForDownload( 3516 download_protection_service->feedback_service()->BeginFeedbackForDownload(
3515 downloads[0]); 3517 downloads[0]);
3516 std::vector<DownloadItem*> updated_downloads; 3518 std::vector<DownloadItem*> updated_downloads;
3517 GetDownloads(browser(), &updated_downloads); 3519 GetDownloads(browser(), &updated_downloads);
3518 ASSERT_TRUE(updated_downloads.empty()); 3520 ASSERT_TRUE(updated_downloads.empty());
3519 } 3521 }
3520 #endif 3522 #endif
OLDNEW
« no previous file with comments | « chrome/browser/domain_reliability/service_factory.cc ('k') | chrome/browser/download/save_package_file_picker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698