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

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

Issue 2823273004: Add new UMA stats for parallelizable download (Closed)
Patch Set: 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
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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 DownloadTargetCallback* callback) { 302 DownloadTargetCallback* callback) {
303 MockDownloadFile* mock_download_file = nullptr; 303 MockDownloadFile* mock_download_file = nullptr;
304 std::unique_ptr<DownloadFile> download_file; 304 std::unique_ptr<DownloadFile> download_file;
305 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _)) 305 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _))
306 .WillOnce(SaveArg<1>(callback)); 306 .WillOnce(SaveArg<1>(callback));
307 307
308 // Only create a DownloadFile if the request was successful. 308 // Only create a DownloadFile if the request was successful.
309 if (create_info_->result == DOWNLOAD_INTERRUPT_REASON_NONE) { 309 if (create_info_->result == DOWNLOAD_INTERRUPT_REASON_NONE) {
310 mock_download_file = new StrictMock<MockDownloadFile>; 310 mock_download_file = new StrictMock<MockDownloadFile>;
311 download_file.reset(mock_download_file); 311 download_file.reset(mock_download_file);
312 EXPECT_CALL(*mock_download_file, Initialize(_, _)) 312 EXPECT_CALL(*mock_download_file, Initialize(_, _, _))
313 .WillOnce(ScheduleCallbackWithParam(DOWNLOAD_INTERRUPT_REASON_NONE)); 313 .WillOnce(ScheduleCallbackWithParam(DOWNLOAD_INTERRUPT_REASON_NONE));
314 EXPECT_CALL(*mock_download_file, FullPath()) 314 EXPECT_CALL(*mock_download_file, FullPath())
315 .WillRepeatedly(ReturnRefOfCopy(base::FilePath())); 315 .WillRepeatedly(ReturnRefOfCopy(base::FilePath()));
316 } 316 }
317 317
318 std::unique_ptr<MockRequestHandle> request_handle = 318 std::unique_ptr<MockRequestHandle> request_handle =
319 base::MakeUnique<NiceMock<MockRequestHandle>>(); 319 base::MakeUnique<NiceMock<MockRequestHandle>>();
320 item->Start(std::move(download_file), std::move(request_handle), 320 item->Start(std::move(download_file), std::move(request_handle),
321 *create_info_); 321 *create_info_);
322 RunAllPendingInMessageLoops(); 322 RunAllPendingInMessageLoops();
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 } 594 }
595 595
596 TEST_F(DownloadItemTest, NotificationAfterTogglePause) { 596 TEST_F(DownloadItemTest, NotificationAfterTogglePause) {
597 DownloadItemImpl* item = CreateDownloadItem(); 597 DownloadItemImpl* item = CreateDownloadItem();
598 TestDownloadItemObserver observer(item); 598 TestDownloadItemObserver observer(item);
599 MockDownloadFile* mock_download_file(new MockDownloadFile); 599 MockDownloadFile* mock_download_file(new MockDownloadFile);
600 std::unique_ptr<DownloadFile> download_file(mock_download_file); 600 std::unique_ptr<DownloadFile> download_file(mock_download_file);
601 std::unique_ptr<DownloadRequestHandleInterface> request_handle( 601 std::unique_ptr<DownloadRequestHandleInterface> request_handle(
602 new NiceMock<MockRequestHandle>); 602 new NiceMock<MockRequestHandle>);
603 603
604 EXPECT_CALL(*mock_download_file, Initialize(_, _)); 604 EXPECT_CALL(*mock_download_file, Initialize(_, _, _));
605 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(_, _)); 605 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(_, _));
606 item->Start(std::move(download_file), std::move(request_handle), 606 item->Start(std::move(download_file), std::move(request_handle),
607 *create_info()); 607 *create_info());
608 608
609 item->Pause(); 609 item->Pause();
610 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated()); 610 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
611 611
612 ASSERT_TRUE(item->IsPaused()); 612 ASSERT_TRUE(item->IsPaused());
613 613
614 item->Resume(); 614 item->Resume();
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 EXPECT_EQ(FILE_PATH_LITERAL("new.name"), 1061 EXPECT_EQ(FILE_PATH_LITERAL("new.name"),
1062 item->GetFileNameToReportUser().value()); 1062 item->GetFileNameToReportUser().value());
1063 CleanupItem(item, download_file, DownloadItem::IN_PROGRESS); 1063 CleanupItem(item, download_file, DownloadItem::IN_PROGRESS);
1064 } 1064 }
1065 1065
1066 // Test to make sure that Start method calls DF initialize properly. 1066 // Test to make sure that Start method calls DF initialize properly.
1067 TEST_F(DownloadItemTest, Start) { 1067 TEST_F(DownloadItemTest, Start) {
1068 MockDownloadFile* mock_download_file(new MockDownloadFile); 1068 MockDownloadFile* mock_download_file(new MockDownloadFile);
1069 std::unique_ptr<DownloadFile> download_file(mock_download_file); 1069 std::unique_ptr<DownloadFile> download_file(mock_download_file);
1070 DownloadItemImpl* item = CreateDownloadItem(); 1070 DownloadItemImpl* item = CreateDownloadItem();
1071 EXPECT_CALL(*mock_download_file, Initialize(_, _)); 1071 EXPECT_CALL(*mock_download_file, Initialize(_, _, _));
1072 std::unique_ptr<DownloadRequestHandleInterface> request_handle( 1072 std::unique_ptr<DownloadRequestHandleInterface> request_handle(
1073 new NiceMock<MockRequestHandle>); 1073 new NiceMock<MockRequestHandle>);
1074 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _)); 1074 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _));
1075 item->Start(std::move(download_file), std::move(request_handle), 1075 item->Start(std::move(download_file), std::move(request_handle),
1076 *create_info()); 1076 *create_info());
1077 RunAllPendingInMessageLoops(); 1077 RunAllPendingInMessageLoops();
1078 1078
1079 CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS); 1079 CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS);
1080 } 1080 }
1081 1081
1082 // Download file and the request should be cancelled as a result of download 1082 // Download file and the request should be cancelled as a result of download
1083 // file initialization failing. 1083 // file initialization failing.
1084 TEST_F(DownloadItemTest, InitDownloadFileFails) { 1084 TEST_F(DownloadItemTest, InitDownloadFileFails) {
1085 DownloadItemImpl* item = CreateDownloadItem(); 1085 DownloadItemImpl* item = CreateDownloadItem();
1086 std::unique_ptr<MockDownloadFile> file = base::MakeUnique<MockDownloadFile>(); 1086 std::unique_ptr<MockDownloadFile> file = base::MakeUnique<MockDownloadFile>();
1087 std::unique_ptr<MockRequestHandle> request_handle = 1087 std::unique_ptr<MockRequestHandle> request_handle =
1088 base::MakeUnique<MockRequestHandle>(); 1088 base::MakeUnique<MockRequestHandle>();
1089 1089
1090 EXPECT_CALL(*file, Cancel()); 1090 EXPECT_CALL(*file, Cancel());
1091 EXPECT_CALL(*request_handle, CancelRequest()); 1091 EXPECT_CALL(*request_handle, CancelRequest());
1092 EXPECT_CALL(*file, Initialize(_, _)) 1092 EXPECT_CALL(*file, Initialize(_, _, _))
1093 .WillOnce(ScheduleCallbackWithParam( 1093 .WillOnce(ScheduleCallbackWithParam(
1094 DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED)); 1094 DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED));
1095 1095
1096 base::RunLoop start_download_loop; 1096 base::RunLoop start_download_loop;
1097 DownloadTargetCallback download_target_callback; 1097 DownloadTargetCallback download_target_callback;
1098 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _)) 1098 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _))
1099 .WillOnce(DoAll(SaveArg<1>(&download_target_callback), 1099 .WillOnce(DoAll(SaveArg<1>(&download_target_callback),
1100 ScheduleClosure(start_download_loop.QuitClosure()))); 1100 ScheduleClosure(start_download_loop.QuitClosure())));
1101 1101
1102 item->Start(std::move(file), std::move(request_handle), *create_info()); 1102 item->Start(std::move(file), std::move(request_handle), *create_info());
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after
2104 // Run through the DII workflow but the embedder cancels the download at target 2104 // Run through the DII workflow but the embedder cancels the download at target
2105 // determination. 2105 // determination.
2106 TEST_P(DownloadItemDestinationUpdateRaceTest, DownloadCancelledByUser) { 2106 TEST_P(DownloadItemDestinationUpdateRaceTest, DownloadCancelledByUser) {
2107 // Expect that the download file and the request will be cancelled as a 2107 // Expect that the download file and the request will be cancelled as a
2108 // result. 2108 // result.
2109 EXPECT_CALL(*file_, Cancel()); 2109 EXPECT_CALL(*file_, Cancel());
2110 EXPECT_CALL(*request_handle_, CancelRequest()); 2110 EXPECT_CALL(*request_handle_, CancelRequest());
2111 2111
2112 base::RunLoop download_start_loop; 2112 base::RunLoop download_start_loop;
2113 DownloadFile::InitializeCallback initialize_callback; 2113 DownloadFile::InitializeCallback initialize_callback;
2114 EXPECT_CALL(*file_, Initialize(_, _)) 2114 EXPECT_CALL(*file_, Initialize(_, _, _))
2115 .WillOnce(DoAll(SaveArg<0>(&initialize_callback), 2115 .WillOnce(DoAll(SaveArg<0>(&initialize_callback),
2116 ScheduleClosure(download_start_loop.QuitClosure()))); 2116 ScheduleClosure(download_start_loop.QuitClosure())));
2117 item_->Start(std::move(file_), std::move(request_handle_), *create_info()); 2117 item_->Start(std::move(file_), std::move(request_handle_), *create_info());
2118 download_start_loop.Run(); 2118 download_start_loop.Run();
2119 2119
2120 base::WeakPtr<DownloadDestinationObserver> destination_observer = 2120 base::WeakPtr<DownloadDestinationObserver> destination_observer =
2121 item_->DestinationObserverAsWeakPtr(); 2121 item_->DestinationObserverAsWeakPtr();
2122 2122
2123 ScheduleObservations(PreInitializeFileObservations(), destination_observer); 2123 ScheduleObservations(PreInitializeFileObservations(), destination_observer);
2124 RunAllPendingInMessageLoops(); 2124 RunAllPendingInMessageLoops();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2157 // DownloadFile expectations since we are about to transfer its ownership to 2157 // DownloadFile expectations since we are about to transfer its ownership to
2158 // the DownloadItem. 2158 // the DownloadItem.
2159 base::RunLoop intermediate_rename_loop; 2159 base::RunLoop intermediate_rename_loop;
2160 DownloadFile::RenameCompletionCallback intermediate_rename_callback; 2160 DownloadFile::RenameCompletionCallback intermediate_rename_callback;
2161 EXPECT_CALL(*file_, RenameAndUniquify(_, _)) 2161 EXPECT_CALL(*file_, RenameAndUniquify(_, _))
2162 .WillOnce(DoAll(SaveArg<1>(&intermediate_rename_callback), 2162 .WillOnce(DoAll(SaveArg<1>(&intermediate_rename_callback),
2163 ScheduleClosure(intermediate_rename_loop.QuitClosure()))); 2163 ScheduleClosure(intermediate_rename_loop.QuitClosure())));
2164 2164
2165 base::RunLoop download_start_loop; 2165 base::RunLoop download_start_loop;
2166 DownloadFile::InitializeCallback initialize_callback; 2166 DownloadFile::InitializeCallback initialize_callback;
2167 EXPECT_CALL(*file_, Initialize(_, _)) 2167 EXPECT_CALL(*file_, Initialize(_, _, _))
2168 .WillOnce(DoAll(SaveArg<0>(&initialize_callback), 2168 .WillOnce(DoAll(SaveArg<0>(&initialize_callback),
2169 ScheduleClosure(download_start_loop.QuitClosure()))); 2169 ScheduleClosure(download_start_loop.QuitClosure())));
2170 2170
2171 item_->Start(std::move(file_), std::move(request_handle_), *create_info()); 2171 item_->Start(std::move(file_), std::move(request_handle_), *create_info());
2172 download_start_loop.Run(); 2172 download_start_loop.Run();
2173 base::WeakPtr<DownloadDestinationObserver> destination_observer = 2173 base::WeakPtr<DownloadDestinationObserver> destination_observer =
2174 item_->DestinationObserverAsWeakPtr(); 2174 item_->DestinationObserverAsWeakPtr();
2175 2175
2176 ScheduleObservations(PreInitializeFileObservations(), destination_observer); 2176 ScheduleObservations(PreInitializeFileObservations(), destination_observer);
2177 RunAllPendingInMessageLoops(); 2177 RunAllPendingInMessageLoops();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2227 // DownloadFile expectations since we are about to transfer its ownership to 2227 // DownloadFile expectations since we are about to transfer its ownership to
2228 // the DownloadItem. 2228 // the DownloadItem.
2229 base::RunLoop intermediate_rename_loop; 2229 base::RunLoop intermediate_rename_loop;
2230 DownloadFile::RenameCompletionCallback intermediate_rename_callback; 2230 DownloadFile::RenameCompletionCallback intermediate_rename_callback;
2231 EXPECT_CALL(*file_, RenameAndUniquify(_, _)) 2231 EXPECT_CALL(*file_, RenameAndUniquify(_, _))
2232 .WillOnce(DoAll(SaveArg<1>(&intermediate_rename_callback), 2232 .WillOnce(DoAll(SaveArg<1>(&intermediate_rename_callback),
2233 ScheduleClosure(intermediate_rename_loop.QuitClosure()))); 2233 ScheduleClosure(intermediate_rename_loop.QuitClosure())));
2234 2234
2235 base::RunLoop download_start_loop; 2235 base::RunLoop download_start_loop;
2236 DownloadFile::InitializeCallback initialize_callback; 2236 DownloadFile::InitializeCallback initialize_callback;
2237 EXPECT_CALL(*file_, Initialize(_, _)) 2237 EXPECT_CALL(*file_, Initialize(_, _, _))
2238 .WillOnce(DoAll(SaveArg<0>(&initialize_callback), 2238 .WillOnce(DoAll(SaveArg<0>(&initialize_callback),
2239 ScheduleClosure(download_start_loop.QuitClosure()))); 2239 ScheduleClosure(download_start_loop.QuitClosure())));
2240 2240
2241 item_->Start(std::move(file_), std::move(request_handle_), *create_info()); 2241 item_->Start(std::move(file_), std::move(request_handle_), *create_info());
2242 download_start_loop.Run(); 2242 download_start_loop.Run();
2243 base::WeakPtr<DownloadDestinationObserver> destination_observer = 2243 base::WeakPtr<DownloadDestinationObserver> destination_observer =
2244 item_->DestinationObserverAsWeakPtr(); 2244 item_->DestinationObserverAsWeakPtr();
2245 2245
2246 ScheduleObservations(PreInitializeFileObservations(), destination_observer); 2246 ScheduleObservations(PreInitializeFileObservations(), destination_observer);
2247 RunAllPendingInMessageLoops(); 2247 RunAllPendingInMessageLoops();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2293 2293
2294 item_->Cancel(true); 2294 item_->Cancel(true);
2295 RunAllPendingInMessageLoops(); 2295 RunAllPendingInMessageLoops();
2296 } 2296 }
2297 2297
2298 TEST(MockDownloadItem, Compiles) { 2298 TEST(MockDownloadItem, Compiles) {
2299 MockDownloadItem mock_item; 2299 MockDownloadItem mock_item;
2300 } 2300 }
2301 2301
2302 } // namespace content 2302 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698