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

Side by Side Diff: content/browser/download/download_item_impl_unittest.cc

Issue 1545243002: Convert Pass()→std::move() in //content/browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 "content/browser/download/download_item_impl.h"
6
5 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility>
6 9
7 #include "base/callback.h" 10 #include "base/callback.h"
8 #include "base/feature_list.h" 11 #include "base/feature_list.h"
9 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
10 #include "base/stl_util.h" 13 #include "base/stl_util.h"
11 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
12 #include "content/browser/byte_stream.h" 15 #include "content/browser/byte_stream.h"
13 #include "content/browser/download/download_create_info.h" 16 #include "content/browser/download/download_create_info.h"
14 #include "content/browser/download/download_file_factory.h" 17 #include "content/browser/download/download_file_factory.h"
15 #include "content/browser/download/download_item_impl.h"
16 #include "content/browser/download/download_item_impl_delegate.h" 18 #include "content/browser/download/download_item_impl_delegate.h"
17 #include "content/browser/download/download_request_handle.h" 19 #include "content/browser/download/download_request_handle.h"
18 #include "content/browser/download/mock_download_file.h" 20 #include "content/browser/download/mock_download_file.h"
19 #include "content/public/browser/download_destination_observer.h" 21 #include "content/public/browser/download_destination_observer.h"
20 #include "content/public/browser/download_interrupt_reasons.h" 22 #include "content/public/browser/download_interrupt_reasons.h"
21 #include "content/public/browser/download_url_parameters.h" 23 #include "content/public/browser/download_url_parameters.h"
22 #include "content/public/common/content_features.h" 24 #include "content/public/common/content_features.h"
23 #include "content/public/test/mock_download_item.h" 25 #include "content/public/test/mock_download_item.h"
24 #include "content/public/test/test_browser_context.h" 26 #include "content/public/test/test_browser_context.h"
25 #include "content/public/test/test_browser_thread.h" 27 #include "content/public/test/test_browser_thread.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 // called. 213 // called.
212 DownloadItemImpl* CreateDownloadItem() { 214 DownloadItemImpl* CreateDownloadItem() {
213 scoped_ptr<DownloadCreateInfo> info; 215 scoped_ptr<DownloadCreateInfo> info;
214 216
215 info.reset(new DownloadCreateInfo()); 217 info.reset(new DownloadCreateInfo());
216 info->save_info = scoped_ptr<DownloadSaveInfo>(new DownloadSaveInfo()); 218 info->save_info = scoped_ptr<DownloadSaveInfo>(new DownloadSaveInfo());
217 info->save_info->prompt_for_save_location = false; 219 info->save_info->prompt_for_save_location = false;
218 info->url_chain.push_back(GURL()); 220 info->url_chain.push_back(GURL());
219 info->etag = "SomethingToSatisfyResumption"; 221 info->etag = "SomethingToSatisfyResumption";
220 222
221 return CreateDownloadItemWithCreateInfo(info.Pass()); 223 return CreateDownloadItemWithCreateInfo(std::move(info));
222 } 224 }
223 225
224 DownloadItemImpl* CreateDownloadItemWithCreateInfo( 226 DownloadItemImpl* CreateDownloadItemWithCreateInfo(
225 scoped_ptr<DownloadCreateInfo> info) { 227 scoped_ptr<DownloadCreateInfo> info) {
226 DownloadItemImpl* download = new DownloadItemImpl( 228 DownloadItemImpl* download = new DownloadItemImpl(
227 &delegate_, next_download_id_++, *(info.get()), net::BoundNetLog()); 229 &delegate_, next_download_id_++, *(info.get()), net::BoundNetLog());
228 allocated_downloads_.insert(download); 230 allocated_downloads_.insert(download);
229 return download; 231 return download;
230 } 232 }
231 233
232 // Add DownloadFile to DownloadItem 234 // Add DownloadFile to DownloadItem
233 MockDownloadFile* AddDownloadFileToDownloadItem( 235 MockDownloadFile* AddDownloadFileToDownloadItem(
234 DownloadItemImpl* item, 236 DownloadItemImpl* item,
235 DownloadItemImplDelegate::DownloadTargetCallback *callback) { 237 DownloadItemImplDelegate::DownloadTargetCallback *callback) {
236 MockDownloadFile* mock_download_file(new StrictMock<MockDownloadFile>); 238 MockDownloadFile* mock_download_file(new StrictMock<MockDownloadFile>);
237 scoped_ptr<DownloadFile> download_file(mock_download_file); 239 scoped_ptr<DownloadFile> download_file(mock_download_file);
238 EXPECT_CALL(*mock_download_file, Initialize(_)); 240 EXPECT_CALL(*mock_download_file, Initialize(_));
239 if (callback) { 241 if (callback) {
240 // Save the callback. 242 // Save the callback.
241 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _)) 243 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _))
242 .WillOnce(SaveArg<1>(callback)); 244 .WillOnce(SaveArg<1>(callback));
243 } else { 245 } else {
244 // Drop it on the floor. 246 // Drop it on the floor.
245 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _)); 247 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _));
246 } 248 }
247 249
248 scoped_ptr<DownloadRequestHandleInterface> request_handle( 250 scoped_ptr<DownloadRequestHandleInterface> request_handle(
249 new NiceMock<MockRequestHandle>); 251 new NiceMock<MockRequestHandle>);
250 item->Start(download_file.Pass(), request_handle.Pass()); 252 item->Start(std::move(download_file), std::move(request_handle));
251 loop_.RunUntilIdle(); 253 loop_.RunUntilIdle();
252 254
253 // So that we don't have a function writing to a stack variable 255 // So that we don't have a function writing to a stack variable
254 // lying around if the above failed. 256 // lying around if the above failed.
255 mock_delegate()->VerifyAndClearExpectations(); 257 mock_delegate()->VerifyAndClearExpectations();
256 EXPECT_CALL(*mock_delegate(), AssertStateConsistent(_)) 258 EXPECT_CALL(*mock_delegate(), AssertStateConsistent(_))
257 .WillRepeatedly(Return()); 259 .WillRepeatedly(Return());
258 EXPECT_CALL(*mock_delegate(), ShouldOpenFileBasedOnExtension(_)) 260 EXPECT_CALL(*mock_delegate(), ShouldOpenFileBasedOnExtension(_))
259 .WillRepeatedly(Return(false)); 261 .WillRepeatedly(Return(false));
260 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(_, _)) 262 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(_, _))
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 mock_download_file = new NiceMock<MockDownloadFile>; 512 mock_download_file = new NiceMock<MockDownloadFile>;
511 download_file.reset(mock_download_file); 513 download_file.reset(mock_download_file);
512 mock_request_handle = new NiceMock<MockRequestHandle>; 514 mock_request_handle = new NiceMock<MockRequestHandle>;
513 request_handle.reset(mock_request_handle); 515 request_handle.reset(mock_request_handle);
514 516
515 ON_CALL(*mock_download_file, FullPath()) 517 ON_CALL(*mock_download_file, FullPath())
516 .WillByDefault(Return(base::FilePath())); 518 .WillByDefault(Return(base::FilePath()));
517 519
518 // Copied key parts of DoIntermediateRename & AddDownloadFileToDownloadItem 520 // Copied key parts of DoIntermediateRename & AddDownloadFileToDownloadItem
519 // to allow for holding onto the request handle. 521 // to allow for holding onto the request handle.
520 item->Start(download_file.Pass(), request_handle.Pass()); 522 item->Start(std::move(download_file), std::move(request_handle));
521 RunAllPendingInMessageLoops(); 523 RunAllPendingInMessageLoops();
522 if (i == 0) { 524 if (i == 0) {
523 // Target determination is only done the first time through. 525 // Target determination is only done the first time through.
524 base::FilePath target_path(kDummyPath); 526 base::FilePath target_path(kDummyPath);
525 base::FilePath intermediate_path( 527 base::FilePath intermediate_path(
526 target_path.InsertBeforeExtensionASCII("x")); 528 target_path.InsertBeforeExtensionASCII("x"));
527 EXPECT_CALL(*mock_download_file, RenameAndUniquify(intermediate_path, _)) 529 EXPECT_CALL(*mock_download_file, RenameAndUniquify(intermediate_path, _))
528 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, 530 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE,
529 intermediate_path)); 531 intermediate_path));
530 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, 532 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE,
(...skipping 16 matching lines...) Expand all
547 TEST_F(DownloadItemTest, ResumeUsingFinalURL) { 549 TEST_F(DownloadItemTest, ResumeUsingFinalURL) {
548 TestBrowserContext test_browser_context; 550 TestBrowserContext test_browser_context;
549 scoped_ptr<DownloadCreateInfo> create_info(new DownloadCreateInfo); 551 scoped_ptr<DownloadCreateInfo> create_info(new DownloadCreateInfo);
550 create_info->save_info = scoped_ptr<DownloadSaveInfo>(new DownloadSaveInfo()); 552 create_info->save_info = scoped_ptr<DownloadSaveInfo>(new DownloadSaveInfo());
551 create_info->save_info->prompt_for_save_location = false; 553 create_info->save_info->prompt_for_save_location = false;
552 create_info->etag = "SomethingToSatisfyResumption"; 554 create_info->etag = "SomethingToSatisfyResumption";
553 create_info->url_chain.push_back(GURL("http://example.com/a")); 555 create_info->url_chain.push_back(GURL("http://example.com/a"));
554 create_info->url_chain.push_back(GURL("http://example.com/b")); 556 create_info->url_chain.push_back(GURL("http://example.com/b"));
555 create_info->url_chain.push_back(GURL("http://example.com/c")); 557 create_info->url_chain.push_back(GURL("http://example.com/c"));
556 558
557 DownloadItemImpl* item = CreateDownloadItemWithCreateInfo(create_info.Pass()); 559 DownloadItemImpl* item =
560 CreateDownloadItemWithCreateInfo(std::move(create_info));
558 TestDownloadItemObserver observer(item); 561 TestDownloadItemObserver observer(item);
559 MockDownloadFile* download_file = 562 MockDownloadFile* download_file =
560 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 563 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
561 564
562 // Interrupt the download, using a continuable interrupt. 565 // Interrupt the download, using a continuable interrupt.
563 EXPECT_CALL(*download_file, FullPath()).WillOnce(Return(base::FilePath())); 566 EXPECT_CALL(*download_file, FullPath()).WillOnce(Return(base::FilePath()));
564 EXPECT_CALL(*download_file, Detach()); 567 EXPECT_CALL(*download_file, Detach());
565 EXPECT_CALL(*mock_delegate(), GetBrowserContext()) 568 EXPECT_CALL(*mock_delegate(), GetBrowserContext())
566 .WillRepeatedly(Return(&test_browser_context)); 569 .WillRepeatedly(Return(&test_browser_context));
567 EXPECT_CALL(*mock_delegate(), MockResumeInterruptedDownload( 570 EXPECT_CALL(*mock_delegate(), MockResumeInterruptedDownload(
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 TEST_F(DownloadItemTest, NotificationAfterTogglePause) { 668 TEST_F(DownloadItemTest, NotificationAfterTogglePause) {
666 DownloadItemImpl* item = CreateDownloadItem(); 669 DownloadItemImpl* item = CreateDownloadItem();
667 TestDownloadItemObserver observer(item); 670 TestDownloadItemObserver observer(item);
668 MockDownloadFile* mock_download_file(new MockDownloadFile); 671 MockDownloadFile* mock_download_file(new MockDownloadFile);
669 scoped_ptr<DownloadFile> download_file(mock_download_file); 672 scoped_ptr<DownloadFile> download_file(mock_download_file);
670 scoped_ptr<DownloadRequestHandleInterface> request_handle( 673 scoped_ptr<DownloadRequestHandleInterface> request_handle(
671 new NiceMock<MockRequestHandle>); 674 new NiceMock<MockRequestHandle>);
672 675
673 EXPECT_CALL(*mock_download_file, Initialize(_)); 676 EXPECT_CALL(*mock_download_file, Initialize(_));
674 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(_, _)); 677 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(_, _));
675 item->Start(download_file.Pass(), request_handle.Pass()); 678 item->Start(std::move(download_file), std::move(request_handle));
676 679
677 item->Pause(); 680 item->Pause();
678 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated()); 681 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
679 682
680 ASSERT_TRUE(item->IsPaused()); 683 ASSERT_TRUE(item->IsPaused());
681 684
682 item->Resume(); 685 item->Resume();
683 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated()); 686 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
684 687
685 RunAllPendingInMessageLoops(); 688 RunAllPendingInMessageLoops();
(...skipping 26 matching lines...) Expand all
712 715
713 // Test to make sure that Start method calls DF initialize properly. 716 // Test to make sure that Start method calls DF initialize properly.
714 TEST_F(DownloadItemTest, Start) { 717 TEST_F(DownloadItemTest, Start) {
715 MockDownloadFile* mock_download_file(new MockDownloadFile); 718 MockDownloadFile* mock_download_file(new MockDownloadFile);
716 scoped_ptr<DownloadFile> download_file(mock_download_file); 719 scoped_ptr<DownloadFile> download_file(mock_download_file);
717 DownloadItemImpl* item = CreateDownloadItem(); 720 DownloadItemImpl* item = CreateDownloadItem();
718 EXPECT_CALL(*mock_download_file, Initialize(_)); 721 EXPECT_CALL(*mock_download_file, Initialize(_));
719 scoped_ptr<DownloadRequestHandleInterface> request_handle( 722 scoped_ptr<DownloadRequestHandleInterface> request_handle(
720 new NiceMock<MockRequestHandle>); 723 new NiceMock<MockRequestHandle>);
721 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _)); 724 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _));
722 item->Start(download_file.Pass(), request_handle.Pass()); 725 item->Start(std::move(download_file), std::move(request_handle));
723 RunAllPendingInMessageLoops(); 726 RunAllPendingInMessageLoops();
724 727
725 CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS); 728 CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS);
726 } 729 }
727 730
728 // Test that the delegate is invoked after the download file is renamed. 731 // Test that the delegate is invoked after the download file is renamed.
729 TEST_F(DownloadItemTest, CallbackAfterRename) { 732 TEST_F(DownloadItemTest, CallbackAfterRename) {
730 DownloadItemImpl* item = CreateDownloadItem(); 733 DownloadItemImpl* item = CreateDownloadItem();
731 DownloadItemImplDelegate::DownloadTargetCallback callback; 734 DownloadItemImplDelegate::DownloadTargetCallback callback;
732 MockDownloadFile* download_file = 735 MockDownloadFile* download_file =
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 base::Unretained(&returned_path))); 1317 base::Unretained(&returned_path)));
1315 RunAllPendingInMessageLoops(); 1318 RunAllPendingInMessageLoops();
1316 EXPECT_TRUE(returned_path.empty()); 1319 EXPECT_TRUE(returned_path.empty());
1317 } 1320 }
1318 1321
1319 TEST(MockDownloadItem, Compiles) { 1322 TEST(MockDownloadItem, Compiles) {
1320 MockDownloadItem mock_item; 1323 MockDownloadItem mock_item;
1321 } 1324 }
1322 1325
1323 } // namespace content 1326 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | content/browser/download/download_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698