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

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

Issue 2823273004: Add new UMA stats for parallelizable download (Closed)
Patch Set: fix test Created 3 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
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | content/browser/download/download_job.h » ('j') | 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 "content/browser/download/download_item_impl.h" 5 #include "content/browser/download/download_item_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <deque> 9 #include <deque>
10 #include <iterator> 10 #include <iterator>
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 DownloadTargetCallback* callback) { 303 DownloadTargetCallback* callback) {
304 MockDownloadFile* mock_download_file = nullptr; 304 MockDownloadFile* mock_download_file = nullptr;
305 std::unique_ptr<DownloadFile> download_file; 305 std::unique_ptr<DownloadFile> download_file;
306 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _)) 306 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _))
307 .WillOnce(SaveArg<1>(callback)); 307 .WillOnce(SaveArg<1>(callback));
308 308
309 // Only create a DownloadFile if the request was successful. 309 // Only create a DownloadFile if the request was successful.
310 if (create_info_->result == DOWNLOAD_INTERRUPT_REASON_NONE) { 310 if (create_info_->result == DOWNLOAD_INTERRUPT_REASON_NONE) {
311 mock_download_file = new StrictMock<MockDownloadFile>; 311 mock_download_file = new StrictMock<MockDownloadFile>;
312 download_file.reset(mock_download_file); 312 download_file.reset(mock_download_file);
313 EXPECT_CALL(*mock_download_file, Initialize(_, _, _)) 313 EXPECT_CALL(*mock_download_file, Initialize(_, _, _, _))
314 .WillOnce(ScheduleCallbackWithParam(DOWNLOAD_INTERRUPT_REASON_NONE)); 314 .WillOnce(ScheduleCallbackWithParam(DOWNLOAD_INTERRUPT_REASON_NONE));
315 EXPECT_CALL(*mock_download_file, FullPath()) 315 EXPECT_CALL(*mock_download_file, FullPath())
316 .WillRepeatedly(ReturnRefOfCopy(base::FilePath())); 316 .WillRepeatedly(ReturnRefOfCopy(base::FilePath()));
317 } 317 }
318 318
319 std::unique_ptr<MockRequestHandle> request_handle = 319 std::unique_ptr<MockRequestHandle> request_handle =
320 base::MakeUnique<NiceMock<MockRequestHandle>>(); 320 base::MakeUnique<NiceMock<MockRequestHandle>>();
321 item->Start(std::move(download_file), std::move(request_handle), 321 item->Start(std::move(download_file), std::move(request_handle),
322 *create_info_); 322 *create_info_);
323 RunAllPendingInMessageLoops(); 323 RunAllPendingInMessageLoops();
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 } 595 }
596 596
597 TEST_F(DownloadItemTest, NotificationAfterTogglePause) { 597 TEST_F(DownloadItemTest, NotificationAfterTogglePause) {
598 DownloadItemImpl* item = CreateDownloadItem(); 598 DownloadItemImpl* item = CreateDownloadItem();
599 TestDownloadItemObserver observer(item); 599 TestDownloadItemObserver observer(item);
600 MockDownloadFile* mock_download_file(new MockDownloadFile); 600 MockDownloadFile* mock_download_file(new MockDownloadFile);
601 std::unique_ptr<DownloadFile> download_file(mock_download_file); 601 std::unique_ptr<DownloadFile> download_file(mock_download_file);
602 std::unique_ptr<DownloadRequestHandleInterface> request_handle( 602 std::unique_ptr<DownloadRequestHandleInterface> request_handle(
603 new NiceMock<MockRequestHandle>); 603 new NiceMock<MockRequestHandle>);
604 604
605 EXPECT_CALL(*mock_download_file, Initialize(_, _, _)); 605 EXPECT_CALL(*mock_download_file, Initialize(_, _, _, _));
606 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(_, _)); 606 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(_, _));
607 item->Start(std::move(download_file), std::move(request_handle), 607 item->Start(std::move(download_file), std::move(request_handle),
608 *create_info()); 608 *create_info());
609 609
610 item->Pause(); 610 item->Pause();
611 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated()); 611 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
612 612
613 ASSERT_TRUE(item->IsPaused()); 613 ASSERT_TRUE(item->IsPaused());
614 614
615 item->Resume(); 615 item->Resume();
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 EXPECT_EQ(FILE_PATH_LITERAL("new.name"), 1062 EXPECT_EQ(FILE_PATH_LITERAL("new.name"),
1063 item->GetFileNameToReportUser().value()); 1063 item->GetFileNameToReportUser().value());
1064 CleanupItem(item, download_file, DownloadItem::IN_PROGRESS); 1064 CleanupItem(item, download_file, DownloadItem::IN_PROGRESS);
1065 } 1065 }
1066 1066
1067 // Test to make sure that Start method calls DF initialize properly. 1067 // Test to make sure that Start method calls DF initialize properly.
1068 TEST_F(DownloadItemTest, Start) { 1068 TEST_F(DownloadItemTest, Start) {
1069 MockDownloadFile* mock_download_file(new MockDownloadFile); 1069 MockDownloadFile* mock_download_file(new MockDownloadFile);
1070 std::unique_ptr<DownloadFile> download_file(mock_download_file); 1070 std::unique_ptr<DownloadFile> download_file(mock_download_file);
1071 DownloadItemImpl* item = CreateDownloadItem(); 1071 DownloadItemImpl* item = CreateDownloadItem();
1072 EXPECT_CALL(*mock_download_file, Initialize(_, _, _)); 1072 EXPECT_CALL(*mock_download_file, Initialize(_, _, _, _));
1073 std::unique_ptr<DownloadRequestHandleInterface> request_handle( 1073 std::unique_ptr<DownloadRequestHandleInterface> request_handle(
1074 new NiceMock<MockRequestHandle>); 1074 new NiceMock<MockRequestHandle>);
1075 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _)); 1075 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _));
1076 item->Start(std::move(download_file), std::move(request_handle), 1076 item->Start(std::move(download_file), std::move(request_handle),
1077 *create_info()); 1077 *create_info());
1078 RunAllPendingInMessageLoops(); 1078 RunAllPendingInMessageLoops();
1079 1079
1080 CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS); 1080 CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS);
1081 } 1081 }
1082 1082
1083 // Download file and the request should be cancelled as a result of download 1083 // Download file and the request should be cancelled as a result of download
1084 // file initialization failing. 1084 // file initialization failing.
1085 TEST_F(DownloadItemTest, InitDownloadFileFails) { 1085 TEST_F(DownloadItemTest, InitDownloadFileFails) {
1086 DownloadItemImpl* item = CreateDownloadItem(); 1086 DownloadItemImpl* item = CreateDownloadItem();
1087 std::unique_ptr<MockDownloadFile> file = base::MakeUnique<MockDownloadFile>(); 1087 std::unique_ptr<MockDownloadFile> file = base::MakeUnique<MockDownloadFile>();
1088 std::unique_ptr<MockRequestHandle> request_handle = 1088 std::unique_ptr<MockRequestHandle> request_handle =
1089 base::MakeUnique<MockRequestHandle>(); 1089 base::MakeUnique<MockRequestHandle>();
1090 1090
1091 EXPECT_CALL(*file, Cancel()); 1091 EXPECT_CALL(*file, Cancel());
1092 EXPECT_CALL(*request_handle, CancelRequest()); 1092 EXPECT_CALL(*request_handle, CancelRequest());
1093 EXPECT_CALL(*file, Initialize(_, _, _)) 1093 EXPECT_CALL(*file, Initialize(_, _, _, _))
1094 .WillOnce(ScheduleCallbackWithParam( 1094 .WillOnce(ScheduleCallbackWithParam(
1095 DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED)); 1095 DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED));
1096 1096
1097 base::RunLoop start_download_loop; 1097 base::RunLoop start_download_loop;
1098 DownloadTargetCallback download_target_callback; 1098 DownloadTargetCallback download_target_callback;
1099 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _)) 1099 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _))
1100 .WillOnce(DoAll(SaveArg<1>(&download_target_callback), 1100 .WillOnce(DoAll(SaveArg<1>(&download_target_callback),
1101 ScheduleClosure(start_download_loop.QuitClosure()))); 1101 ScheduleClosure(start_download_loop.QuitClosure())));
1102 1102
1103 item->Start(std::move(file), std::move(request_handle), *create_info()); 1103 item->Start(std::move(file), std::move(request_handle), *create_info());
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 // Run through the DII workflow but the embedder cancels the download at target 2120 // Run through the DII workflow but the embedder cancels the download at target
2121 // determination. 2121 // determination.
2122 TEST_P(DownloadItemDestinationUpdateRaceTest, DownloadCancelledByUser) { 2122 TEST_P(DownloadItemDestinationUpdateRaceTest, DownloadCancelledByUser) {
2123 // Expect that the download file and the request will be cancelled as a 2123 // Expect that the download file and the request will be cancelled as a
2124 // result. 2124 // result.
2125 EXPECT_CALL(*file_, Cancel()); 2125 EXPECT_CALL(*file_, Cancel());
2126 EXPECT_CALL(*request_handle_, CancelRequest()); 2126 EXPECT_CALL(*request_handle_, CancelRequest());
2127 2127
2128 base::RunLoop download_start_loop; 2128 base::RunLoop download_start_loop;
2129 DownloadFile::InitializeCallback initialize_callback; 2129 DownloadFile::InitializeCallback initialize_callback;
2130 EXPECT_CALL(*file_, Initialize(_, _, _)) 2130 EXPECT_CALL(*file_, Initialize(_, _, _, _))
2131 .WillOnce(DoAll(SaveArg<0>(&initialize_callback), 2131 .WillOnce(DoAll(SaveArg<0>(&initialize_callback),
2132 ScheduleClosure(download_start_loop.QuitClosure()))); 2132 ScheduleClosure(download_start_loop.QuitClosure())));
2133 item_->Start(std::move(file_), std::move(request_handle_), *create_info()); 2133 item_->Start(std::move(file_), std::move(request_handle_), *create_info());
2134 download_start_loop.Run(); 2134 download_start_loop.Run();
2135 2135
2136 base::WeakPtr<DownloadDestinationObserver> destination_observer = 2136 base::WeakPtr<DownloadDestinationObserver> destination_observer =
2137 item_->DestinationObserverAsWeakPtr(); 2137 item_->DestinationObserverAsWeakPtr();
2138 2138
2139 ScheduleObservations(PreInitializeFileObservations(), destination_observer); 2139 ScheduleObservations(PreInitializeFileObservations(), destination_observer);
2140 RunAllPendingInMessageLoops(); 2140 RunAllPendingInMessageLoops();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2173 // DownloadFile expectations since we are about to transfer its ownership to 2173 // DownloadFile expectations since we are about to transfer its ownership to
2174 // the DownloadItem. 2174 // the DownloadItem.
2175 base::RunLoop intermediate_rename_loop; 2175 base::RunLoop intermediate_rename_loop;
2176 DownloadFile::RenameCompletionCallback intermediate_rename_callback; 2176 DownloadFile::RenameCompletionCallback intermediate_rename_callback;
2177 EXPECT_CALL(*file_, RenameAndUniquify(_, _)) 2177 EXPECT_CALL(*file_, RenameAndUniquify(_, _))
2178 .WillOnce(DoAll(SaveArg<1>(&intermediate_rename_callback), 2178 .WillOnce(DoAll(SaveArg<1>(&intermediate_rename_callback),
2179 ScheduleClosure(intermediate_rename_loop.QuitClosure()))); 2179 ScheduleClosure(intermediate_rename_loop.QuitClosure())));
2180 2180
2181 base::RunLoop download_start_loop; 2181 base::RunLoop download_start_loop;
2182 DownloadFile::InitializeCallback initialize_callback; 2182 DownloadFile::InitializeCallback initialize_callback;
2183 EXPECT_CALL(*file_, Initialize(_, _, _)) 2183 EXPECT_CALL(*file_, Initialize(_, _, _, _))
2184 .WillOnce(DoAll(SaveArg<0>(&initialize_callback), 2184 .WillOnce(DoAll(SaveArg<0>(&initialize_callback),
2185 ScheduleClosure(download_start_loop.QuitClosure()))); 2185 ScheduleClosure(download_start_loop.QuitClosure())));
2186 2186
2187 item_->Start(std::move(file_), std::move(request_handle_), *create_info()); 2187 item_->Start(std::move(file_), std::move(request_handle_), *create_info());
2188 download_start_loop.Run(); 2188 download_start_loop.Run();
2189 base::WeakPtr<DownloadDestinationObserver> destination_observer = 2189 base::WeakPtr<DownloadDestinationObserver> destination_observer =
2190 item_->DestinationObserverAsWeakPtr(); 2190 item_->DestinationObserverAsWeakPtr();
2191 2191
2192 ScheduleObservations(PreInitializeFileObservations(), destination_observer); 2192 ScheduleObservations(PreInitializeFileObservations(), destination_observer);
2193 RunAllPendingInMessageLoops(); 2193 RunAllPendingInMessageLoops();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2243 // DownloadFile expectations since we are about to transfer its ownership to 2243 // DownloadFile expectations since we are about to transfer its ownership to
2244 // the DownloadItem. 2244 // the DownloadItem.
2245 base::RunLoop intermediate_rename_loop; 2245 base::RunLoop intermediate_rename_loop;
2246 DownloadFile::RenameCompletionCallback intermediate_rename_callback; 2246 DownloadFile::RenameCompletionCallback intermediate_rename_callback;
2247 EXPECT_CALL(*file_, RenameAndUniquify(_, _)) 2247 EXPECT_CALL(*file_, RenameAndUniquify(_, _))
2248 .WillOnce(DoAll(SaveArg<1>(&intermediate_rename_callback), 2248 .WillOnce(DoAll(SaveArg<1>(&intermediate_rename_callback),
2249 ScheduleClosure(intermediate_rename_loop.QuitClosure()))); 2249 ScheduleClosure(intermediate_rename_loop.QuitClosure())));
2250 2250
2251 base::RunLoop download_start_loop; 2251 base::RunLoop download_start_loop;
2252 DownloadFile::InitializeCallback initialize_callback; 2252 DownloadFile::InitializeCallback initialize_callback;
2253 EXPECT_CALL(*file_, Initialize(_, _, _)) 2253 EXPECT_CALL(*file_, Initialize(_, _, _, _))
2254 .WillOnce(DoAll(SaveArg<0>(&initialize_callback), 2254 .WillOnce(DoAll(SaveArg<0>(&initialize_callback),
2255 ScheduleClosure(download_start_loop.QuitClosure()))); 2255 ScheduleClosure(download_start_loop.QuitClosure())));
2256 2256
2257 item_->Start(std::move(file_), std::move(request_handle_), *create_info()); 2257 item_->Start(std::move(file_), std::move(request_handle_), *create_info());
2258 download_start_loop.Run(); 2258 download_start_loop.Run();
2259 base::WeakPtr<DownloadDestinationObserver> destination_observer = 2259 base::WeakPtr<DownloadDestinationObserver> destination_observer =
2260 item_->DestinationObserverAsWeakPtr(); 2260 item_->DestinationObserverAsWeakPtr();
2261 2261
2262 ScheduleObservations(PreInitializeFileObservations(), destination_observer); 2262 ScheduleObservations(PreInitializeFileObservations(), destination_observer);
2263 RunAllPendingInMessageLoops(); 2263 RunAllPendingInMessageLoops();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2309 2309
2310 item_->Cancel(true); 2310 item_->Cancel(true);
2311 RunAllPendingInMessageLoops(); 2311 RunAllPendingInMessageLoops();
2312 } 2312 }
2313 2313
2314 TEST(MockDownloadItem, Compiles) { 2314 TEST(MockDownloadItem, Compiles) {
2315 MockDownloadItem mock_item; 2315 MockDownloadItem mock_item;
2316 } 2316 }
2317 2317
2318 } // namespace content 2318 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | content/browser/download/download_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698