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

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

Issue 511483002: Remove implicit conversions from scoped_refptr to T* in chrome/browser/download/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | 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/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 3174 matching lines...) Expand 10 before | Expand all | Expand 10 after
3185 CommandLine::ForCurrentProcess()->AppendSwitch( 3185 CommandLine::ForCurrentProcess()->AppendSwitch(
3186 switches::kEnableDownloadResumption); 3186 switches::kEnableDownloadResumption);
3187 scoped_refptr<content::TestFileErrorInjector> error_injector( 3187 scoped_refptr<content::TestFileErrorInjector> error_injector(
3188 content::TestFileErrorInjector::Create( 3188 content::TestFileErrorInjector::Create(
3189 DownloadManagerForBrowser(browser()))); 3189 DownloadManagerForBrowser(browser())));
3190 scoped_ptr<content::DownloadTestObserver> completion_observer( 3190 scoped_ptr<content::DownloadTestObserver> completion_observer(
3191 CreateWaiter(browser(), 1)); 3191 CreateWaiter(browser(), 1));
3192 EnableFileChooser(true); 3192 EnableFileChooser(true);
3193 3193
3194 DownloadItem* download = StartMockDownloadAndInjectError( 3194 DownloadItem* download = StartMockDownloadAndInjectError(
3195 error_injector, 3195 error_injector.get(), content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED);
3196 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED);
3197 ASSERT_TRUE(download); 3196 ASSERT_TRUE(download);
3198 3197
3199 download->Resume(); 3198 download->Resume();
3200 completion_observer->WaitForFinished(); 3199 completion_observer->WaitForFinished();
3201 3200
3202 EXPECT_EQ( 3201 EXPECT_EQ(
3203 1u, completion_observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 3202 1u, completion_observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
3204 EXPECT_FALSE(DidShowFileChooser()); 3203 EXPECT_FALSE(DidShowFileChooser());
3205 } 3204 }
3206 3205
3207 // A download that's interrupted due to a reason that indicates that the target 3206 // A download that's interrupted due to a reason that indicates that the target
3208 // path is invalid or unusable should cause a prompt to be displayed on 3207 // path is invalid or unusable should cause a prompt to be displayed on
3209 // resumption. 3208 // resumption.
3210 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_WithPrompt) { 3209 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_WithPrompt) {
3211 CommandLine::ForCurrentProcess()->AppendSwitch( 3210 CommandLine::ForCurrentProcess()->AppendSwitch(
3212 switches::kEnableDownloadResumption); 3211 switches::kEnableDownloadResumption);
3213 scoped_refptr<content::TestFileErrorInjector> error_injector( 3212 scoped_refptr<content::TestFileErrorInjector> error_injector(
3214 content::TestFileErrorInjector::Create( 3213 content::TestFileErrorInjector::Create(
3215 DownloadManagerForBrowser(browser()))); 3214 DownloadManagerForBrowser(browser())));
3216 scoped_ptr<content::DownloadTestObserver> completion_observer( 3215 scoped_ptr<content::DownloadTestObserver> completion_observer(
3217 CreateWaiter(browser(), 1)); 3216 CreateWaiter(browser(), 1));
3218 EnableFileChooser(true); 3217 EnableFileChooser(true);
3219 3218
3220 DownloadItem* download = StartMockDownloadAndInjectError( 3219 DownloadItem* download = StartMockDownloadAndInjectError(
3221 error_injector, 3220 error_injector.get(), content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE);
3222 content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE);
3223 ASSERT_TRUE(download); 3221 ASSERT_TRUE(download);
3224 3222
3225 download->Resume(); 3223 download->Resume();
3226 completion_observer->WaitForFinished(); 3224 completion_observer->WaitForFinished();
3227 3225
3228 EXPECT_EQ( 3226 EXPECT_EQ(
3229 1u, completion_observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 3227 1u, completion_observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
3230 EXPECT_TRUE(DidShowFileChooser()); 3228 EXPECT_TRUE(DidShowFileChooser());
3231 } 3229 }
3232 3230
3233 // The user shouldn't be prompted on a resumed download unless a prompt is 3231 // The user shouldn't be prompted on a resumed download unless a prompt is
3234 // necessary due to the interrupt reason. 3232 // necessary due to the interrupt reason.
3235 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_WithPromptAlways) { 3233 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_WithPromptAlways) {
3236 CommandLine::ForCurrentProcess()->AppendSwitch( 3234 CommandLine::ForCurrentProcess()->AppendSwitch(
3237 switches::kEnableDownloadResumption); 3235 switches::kEnableDownloadResumption);
3238 browser()->profile()->GetPrefs()->SetBoolean( 3236 browser()->profile()->GetPrefs()->SetBoolean(
3239 prefs::kPromptForDownload, true); 3237 prefs::kPromptForDownload, true);
3240 scoped_refptr<content::TestFileErrorInjector> error_injector( 3238 scoped_refptr<content::TestFileErrorInjector> error_injector(
3241 content::TestFileErrorInjector::Create( 3239 content::TestFileErrorInjector::Create(
3242 DownloadManagerForBrowser(browser()))); 3240 DownloadManagerForBrowser(browser())));
3243 scoped_ptr<content::DownloadTestObserver> completion_observer( 3241 scoped_ptr<content::DownloadTestObserver> completion_observer(
3244 CreateWaiter(browser(), 1)); 3242 CreateWaiter(browser(), 1));
3245 EnableFileChooser(true); 3243 EnableFileChooser(true);
3246 3244
3247 DownloadItem* download = StartMockDownloadAndInjectError( 3245 DownloadItem* download = StartMockDownloadAndInjectError(
3248 error_injector, 3246 error_injector.get(), content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED);
3249 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED);
3250 ASSERT_TRUE(download); 3247 ASSERT_TRUE(download);
3251 3248
3252 // Prompts the user initially because of the kPromptForDownload preference. 3249 // Prompts the user initially because of the kPromptForDownload preference.
3253 EXPECT_TRUE(DidShowFileChooser()); 3250 EXPECT_TRUE(DidShowFileChooser());
3254 3251
3255 download->Resume(); 3252 download->Resume();
3256 completion_observer->WaitForFinished(); 3253 completion_observer->WaitForFinished();
3257 3254
3258 EXPECT_EQ( 3255 EXPECT_EQ(
3259 1u, completion_observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 3256 1u, completion_observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
3260 // Shouldn't prompt for resumption. 3257 // Shouldn't prompt for resumption.
3261 EXPECT_FALSE(DidShowFileChooser()); 3258 EXPECT_FALSE(DidShowFileChooser());
3262 } 3259 }
3263 3260
3264 // A download that is interrupted due to a transient error should be resumed 3261 // A download that is interrupted due to a transient error should be resumed
3265 // automatically. 3262 // automatically.
3266 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_Automatic) { 3263 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_Automatic) {
3267 CommandLine::ForCurrentProcess()->AppendSwitch( 3264 CommandLine::ForCurrentProcess()->AppendSwitch(
3268 switches::kEnableDownloadResumption); 3265 switches::kEnableDownloadResumption);
3269 scoped_refptr<content::TestFileErrorInjector> error_injector( 3266 scoped_refptr<content::TestFileErrorInjector> error_injector(
3270 content::TestFileErrorInjector::Create( 3267 content::TestFileErrorInjector::Create(
3271 DownloadManagerForBrowser(browser()))); 3268 DownloadManagerForBrowser(browser())));
3272 3269
3273 DownloadItem* download = StartMockDownloadAndInjectError( 3270 DownloadItem* download = StartMockDownloadAndInjectError(
3274 error_injector, 3271 error_injector.get(),
3275 content::DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR); 3272 content::DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR);
3276 ASSERT_TRUE(download); 3273 ASSERT_TRUE(download);
3277 3274
3278 // The number of times this the download is resumed automatically is defined 3275 // The number of times this the download is resumed automatically is defined
3279 // in DownloadItemImpl::kMaxAutoResumeAttempts. The number of DownloadFiles 3276 // in DownloadItemImpl::kMaxAutoResumeAttempts. The number of DownloadFiles
3280 // created should be that number + 1 (for the original download request). We 3277 // created should be that number + 1 (for the original download request). We
3281 // only care that it is greater than 1. 3278 // only care that it is greater than 1.
3282 EXPECT_GT(1u, error_injector->TotalFileCount()); 3279 EXPECT_GT(1u, error_injector->TotalFileCount());
3283 } 3280 }
3284 3281
3285 // An interrupting download should be resumable multiple times. 3282 // An interrupting download should be resumable multiple times.
3286 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_MultipleAttempts) { 3283 IN_PROC_BROWSER_TEST_F(DownloadTest, Resumption_MultipleAttempts) {
3287 CommandLine::ForCurrentProcess()->AppendSwitch( 3284 CommandLine::ForCurrentProcess()->AppendSwitch(
3288 switches::kEnableDownloadResumption); 3285 switches::kEnableDownloadResumption);
3289 scoped_refptr<content::TestFileErrorInjector> error_injector( 3286 scoped_refptr<content::TestFileErrorInjector> error_injector(
3290 content::TestFileErrorInjector::Create( 3287 content::TestFileErrorInjector::Create(
3291 DownloadManagerForBrowser(browser()))); 3288 DownloadManagerForBrowser(browser())));
3292 scoped_ptr<DownloadTestObserverNotInProgress> completion_observer( 3289 scoped_ptr<DownloadTestObserverNotInProgress> completion_observer(
3293 new DownloadTestObserverNotInProgress( 3290 new DownloadTestObserverNotInProgress(
3294 DownloadManagerForBrowser(browser()), 1)); 3291 DownloadManagerForBrowser(browser()), 1));
3295 // Wait for two transitions to a resumable state 3292 // Wait for two transitions to a resumable state
3296 scoped_ptr<content::DownloadTestObserver> resumable_observer( 3293 scoped_ptr<content::DownloadTestObserver> resumable_observer(
3297 new DownloadTestObserverResumable( 3294 new DownloadTestObserverResumable(
3298 DownloadManagerForBrowser(browser()), 2)); 3295 DownloadManagerForBrowser(browser()), 2));
3299 3296
3300 EnableFileChooser(true); 3297 EnableFileChooser(true);
3301 DownloadItem* download = StartMockDownloadAndInjectError( 3298 DownloadItem* download = StartMockDownloadAndInjectError(
3302 error_injector, 3299 error_injector.get(), content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED);
3303 content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED);
3304 ASSERT_TRUE(download); 3300 ASSERT_TRUE(download);
3305 3301
3306 content::TestFileErrorInjector::FileErrorInfo error_info; 3302 content::TestFileErrorInjector::FileErrorInfo error_info;
3307 error_info.url = download->GetOriginalUrl().spec(); 3303 error_info.url = download->GetOriginalUrl().spec();
3308 error_info.code = content::TestFileErrorInjector::FILE_OPERATION_WRITE; 3304 error_info.code = content::TestFileErrorInjector::FILE_OPERATION_WRITE;
3309 error_info.operation_instance = 0; 3305 error_info.operation_instance = 0;
3310 error_info.error = content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED; 3306 error_info.error = content::DOWNLOAD_INTERRUPT_REASON_FILE_FAILED;
3311 error_injector->AddError(error_info); 3307 error_injector->AddError(error_info);
3312 error_injector->InjectErrors(); 3308 error_injector->InjectErrors();
3313 3309
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3391 *(downloads[0]))); 3387 *(downloads[0])));
3392 3388
3393 // Begin feedback and check that the file is "stolen". 3389 // Begin feedback and check that the file is "stolen".
3394 download_protection_service->feedback_service()->BeginFeedbackForDownload( 3390 download_protection_service->feedback_service()->BeginFeedbackForDownload(
3395 downloads[0]); 3391 downloads[0]);
3396 std::vector<DownloadItem*> updated_downloads; 3392 std::vector<DownloadItem*> updated_downloads;
3397 GetDownloads(browser(), &updated_downloads); 3393 GetDownloads(browser(), &updated_downloads);
3398 ASSERT_TRUE(updated_downloads.empty()); 3394 ASSERT_TRUE(updated_downloads.empty());
3399 } 3395 }
3400 #endif 3396 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698