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

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

Issue 1549113002: Switch to standard integer types in content/browser/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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 <stddef.h>
6 #include <stdint.h>
7
5 #include <set> 8 #include <set>
6 #include <string> 9 #include <string>
7 10
8 #include "base/bind.h" 11 #include "base/bind.h"
9 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
12 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
13 #include "base/stl_util.h" 17 #include "base/stl_util.h"
14 #include "base/strings/string16.h" 18 #include "base/strings/string16.h"
15 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
17 #include "build/build_config.h" 21 #include "build/build_config.h"
18 #include "content/browser/byte_stream.h" 22 #include "content/browser/byte_stream.h"
19 #include "content/browser/download/download_create_info.h" 23 #include "content/browser/download/download_create_info.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 MOCK_METHOD1(AddObserver, void(DownloadItem::Observer*)); 103 MOCK_METHOD1(AddObserver, void(DownloadItem::Observer*));
100 MOCK_METHOD1(RemoveObserver, void(DownloadItem::Observer*)); 104 MOCK_METHOD1(RemoveObserver, void(DownloadItem::Observer*));
101 MOCK_METHOD0(UpdateObservers, void()); 105 MOCK_METHOD0(UpdateObservers, void());
102 MOCK_METHOD0(CanShowInFolder, bool()); 106 MOCK_METHOD0(CanShowInFolder, bool());
103 MOCK_METHOD0(CanOpenDownload, bool()); 107 MOCK_METHOD0(CanOpenDownload, bool());
104 MOCK_METHOD0(ShouldOpenFileBasedOnExtension, bool()); 108 MOCK_METHOD0(ShouldOpenFileBasedOnExtension, bool());
105 MOCK_METHOD0(OpenDownload, void()); 109 MOCK_METHOD0(OpenDownload, void());
106 MOCK_METHOD0(ShowDownloadInShell, void()); 110 MOCK_METHOD0(ShowDownloadInShell, void());
107 MOCK_METHOD0(ValidateDangerousDownload, void()); 111 MOCK_METHOD0(ValidateDangerousDownload, void());
108 MOCK_METHOD1(StealDangerousDownload, void(const AcquireFileCallback&)); 112 MOCK_METHOD1(StealDangerousDownload, void(const AcquireFileCallback&));
109 MOCK_METHOD3(UpdateProgress, void(int64, int64, const std::string&)); 113 MOCK_METHOD3(UpdateProgress, void(int64_t, int64_t, const std::string&));
110 MOCK_METHOD1(Cancel, void(bool)); 114 MOCK_METHOD1(Cancel, void(bool));
111 MOCK_METHOD0(MarkAsComplete, void()); 115 MOCK_METHOD0(MarkAsComplete, void());
112 MOCK_METHOD1(OnAllDataSaved, void(const std::string&)); 116 MOCK_METHOD1(OnAllDataSaved, void(const std::string&));
113 MOCK_METHOD0(OnDownloadedFileRemoved, void()); 117 MOCK_METHOD0(OnDownloadedFileRemoved, void());
114 void Start(scoped_ptr<DownloadFile> download_file, 118 void Start(scoped_ptr<DownloadFile> download_file,
115 scoped_ptr<DownloadRequestHandleInterface> req_handle) override { 119 scoped_ptr<DownloadRequestHandleInterface> req_handle) override {
116 MockStart(download_file.get(), req_handle.get()); 120 MockStart(download_file.get(), req_handle.get());
117 } 121 }
118 122
119 MOCK_METHOD2(MockStart, void(DownloadFile*, DownloadRequestHandleInterface*)); 123 MOCK_METHOD2(MockStart, void(DownloadFile*, DownloadRequestHandleInterface*));
120 124
121 MOCK_METHOD0(Remove, void()); 125 MOCK_METHOD0(Remove, void());
122 MOCK_CONST_METHOD1(TimeRemaining, bool(base::TimeDelta*)); 126 MOCK_CONST_METHOD1(TimeRemaining, bool(base::TimeDelta*));
123 MOCK_CONST_METHOD0(CurrentSpeed, int64()); 127 MOCK_CONST_METHOD0(CurrentSpeed, int64_t());
124 MOCK_CONST_METHOD0(PercentComplete, int()); 128 MOCK_CONST_METHOD0(PercentComplete, int());
125 MOCK_CONST_METHOD0(AllDataSaved, bool()); 129 MOCK_CONST_METHOD0(AllDataSaved, bool());
126 MOCK_CONST_METHOD1(MatchesQuery, bool(const base::string16& query)); 130 MOCK_CONST_METHOD1(MatchesQuery, bool(const base::string16& query));
127 MOCK_CONST_METHOD0(IsDone, bool()); 131 MOCK_CONST_METHOD0(IsDone, bool());
128 MOCK_CONST_METHOD0(GetFullPath, const base::FilePath&()); 132 MOCK_CONST_METHOD0(GetFullPath, const base::FilePath&());
129 MOCK_CONST_METHOD0(GetTargetFilePath, const base::FilePath&()); 133 MOCK_CONST_METHOD0(GetTargetFilePath, const base::FilePath&());
130 MOCK_CONST_METHOD0(GetTargetDisposition, TargetDisposition()); 134 MOCK_CONST_METHOD0(GetTargetDisposition, TargetDisposition());
131 MOCK_METHOD1(OnContentCheckCompleted, void(DownloadDangerType)); 135 MOCK_METHOD1(OnContentCheckCompleted, void(DownloadDangerType));
132 MOCK_CONST_METHOD0(GetState, DownloadState()); 136 MOCK_CONST_METHOD0(GetState, DownloadState());
133 MOCK_CONST_METHOD0(GetUrlChain, const std::vector<GURL>&()); 137 MOCK_CONST_METHOD0(GetUrlChain, const std::vector<GURL>&());
134 MOCK_METHOD1(SetTotalBytes, void(int64)); 138 MOCK_METHOD1(SetTotalBytes, void(int64_t));
135 MOCK_CONST_METHOD0(GetURL, const GURL&()); 139 MOCK_CONST_METHOD0(GetURL, const GURL&());
136 MOCK_CONST_METHOD0(GetOriginalUrl, const GURL&()); 140 MOCK_CONST_METHOD0(GetOriginalUrl, const GURL&());
137 MOCK_CONST_METHOD0(GetReferrerUrl, const GURL&()); 141 MOCK_CONST_METHOD0(GetReferrerUrl, const GURL&());
138 MOCK_CONST_METHOD0(GetTabUrl, const GURL&()); 142 MOCK_CONST_METHOD0(GetTabUrl, const GURL&());
139 MOCK_CONST_METHOD0(GetTabReferrerUrl, const GURL&()); 143 MOCK_CONST_METHOD0(GetTabReferrerUrl, const GURL&());
140 MOCK_CONST_METHOD0(GetSuggestedFilename, std::string()); 144 MOCK_CONST_METHOD0(GetSuggestedFilename, std::string());
141 MOCK_CONST_METHOD0(GetContentDisposition, std::string()); 145 MOCK_CONST_METHOD0(GetContentDisposition, std::string());
142 MOCK_CONST_METHOD0(GetMimeType, std::string()); 146 MOCK_CONST_METHOD0(GetMimeType, std::string());
143 MOCK_CONST_METHOD0(GetOriginalMimeType, std::string()); 147 MOCK_CONST_METHOD0(GetOriginalMimeType, std::string());
144 MOCK_CONST_METHOD0(GetReferrerCharset, std::string()); 148 MOCK_CONST_METHOD0(GetReferrerCharset, std::string());
145 MOCK_CONST_METHOD0(GetRemoteAddress, std::string()); 149 MOCK_CONST_METHOD0(GetRemoteAddress, std::string());
146 MOCK_CONST_METHOD0(GetTotalBytes, int64()); 150 MOCK_CONST_METHOD0(GetTotalBytes, int64_t());
147 MOCK_CONST_METHOD0(GetReceivedBytes, int64()); 151 MOCK_CONST_METHOD0(GetReceivedBytes, int64_t());
148 MOCK_CONST_METHOD0(GetHashState, const std::string&()); 152 MOCK_CONST_METHOD0(GetHashState, const std::string&());
149 MOCK_CONST_METHOD0(GetHash, const std::string&()); 153 MOCK_CONST_METHOD0(GetHash, const std::string&());
150 MOCK_CONST_METHOD0(GetId, uint32()); 154 MOCK_CONST_METHOD0(GetId, uint32_t());
151 MOCK_CONST_METHOD0(GetStartTime, base::Time()); 155 MOCK_CONST_METHOD0(GetStartTime, base::Time());
152 MOCK_CONST_METHOD0(GetEndTime, base::Time()); 156 MOCK_CONST_METHOD0(GetEndTime, base::Time());
153 MOCK_METHOD0(GetDownloadManager, DownloadManager*()); 157 MOCK_METHOD0(GetDownloadManager, DownloadManager*());
154 MOCK_CONST_METHOD0(IsPaused, bool()); 158 MOCK_CONST_METHOD0(IsPaused, bool());
155 MOCK_CONST_METHOD0(GetOpenWhenComplete, bool()); 159 MOCK_CONST_METHOD0(GetOpenWhenComplete, bool());
156 MOCK_METHOD1(SetOpenWhenComplete, void(bool)); 160 MOCK_METHOD1(SetOpenWhenComplete, void(bool));
157 MOCK_CONST_METHOD0(GetFileExternallyRemoved, bool()); 161 MOCK_CONST_METHOD0(GetFileExternallyRemoved, bool());
158 MOCK_CONST_METHOD0(GetDangerType, DownloadDangerType()); 162 MOCK_CONST_METHOD0(GetDangerType, DownloadDangerType());
159 MOCK_CONST_METHOD0(IsDangerous, bool()); 163 MOCK_CONST_METHOD0(IsDangerous, bool());
160 MOCK_METHOD0(GetAutoOpened, bool()); 164 MOCK_METHOD0(GetAutoOpened, bool());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // Generally used during teardown. 229 // Generally used during teardown.
226 MockDownloadItemImpl* PopItem(); 230 MockDownloadItemImpl* PopItem();
227 231
228 // Should be called when the item of this id is removed so that 232 // Should be called when the item of this id is removed so that
229 // we don't keep dangling pointers. 233 // we don't keep dangling pointers.
230 void RemoveItem(int id); 234 void RemoveItem(int id);
231 235
232 // Overridden methods from DownloadItemFactory. 236 // Overridden methods from DownloadItemFactory.
233 DownloadItemImpl* CreatePersistedItem( 237 DownloadItemImpl* CreatePersistedItem(
234 DownloadItemImplDelegate* delegate, 238 DownloadItemImplDelegate* delegate,
235 uint32 download_id, 239 uint32_t download_id,
236 const base::FilePath& current_path, 240 const base::FilePath& current_path,
237 const base::FilePath& target_path, 241 const base::FilePath& target_path,
238 const std::vector<GURL>& url_chain, 242 const std::vector<GURL>& url_chain,
239 const GURL& referrer_url, 243 const GURL& referrer_url,
240 const std::string& mime_type, 244 const std::string& mime_type,
241 const std::string& original_mime_type, 245 const std::string& original_mime_type,
242 const base::Time& start_time, 246 const base::Time& start_time,
243 const base::Time& end_time, 247 const base::Time& end_time,
244 const std::string& etag, 248 const std::string& etag,
245 const std::string& last_modofied, 249 const std::string& last_modofied,
246 int64 received_bytes, 250 int64_t received_bytes,
247 int64 total_bytes, 251 int64_t total_bytes,
248 DownloadItem::DownloadState state, 252 DownloadItem::DownloadState state,
249 DownloadDangerType danger_type, 253 DownloadDangerType danger_type,
250 DownloadInterruptReason interrupt_reason, 254 DownloadInterruptReason interrupt_reason,
251 bool opened, 255 bool opened,
252 const net::BoundNetLog& bound_net_log) override; 256 const net::BoundNetLog& bound_net_log) override;
253 DownloadItemImpl* CreateActiveItem( 257 DownloadItemImpl* CreateActiveItem(
254 DownloadItemImplDelegate* delegate, 258 DownloadItemImplDelegate* delegate,
255 uint32 download_id, 259 uint32_t download_id,
256 const DownloadCreateInfo& info, 260 const DownloadCreateInfo& info,
257 const net::BoundNetLog& bound_net_log) override; 261 const net::BoundNetLog& bound_net_log) override;
258 DownloadItemImpl* CreateSavePageItem( 262 DownloadItemImpl* CreateSavePageItem(
259 DownloadItemImplDelegate* delegate, 263 DownloadItemImplDelegate* delegate,
260 uint32 download_id, 264 uint32_t download_id,
261 const base::FilePath& path, 265 const base::FilePath& path,
262 const GURL& url, 266 const GURL& url,
263 const std::string& mime_type, 267 const std::string& mime_type,
264 scoped_ptr<DownloadRequestHandleInterface> request_handle, 268 scoped_ptr<DownloadRequestHandleInterface> request_handle,
265 const net::BoundNetLog& bound_net_log) override; 269 const net::BoundNetLog& bound_net_log) override;
266 270
267 private: 271 private:
268 std::map<uint32, MockDownloadItemImpl*> items_; 272 std::map<uint32_t, MockDownloadItemImpl*> items_;
269 DownloadItemImplDelegate item_delegate_; 273 DownloadItemImplDelegate item_delegate_;
270 274
271 DISALLOW_COPY_AND_ASSIGN(MockDownloadItemFactory); 275 DISALLOW_COPY_AND_ASSIGN(MockDownloadItemFactory);
272 }; 276 };
273 277
274 MockDownloadItemFactory::MockDownloadItemFactory() {} 278 MockDownloadItemFactory::MockDownloadItemFactory() {}
275 279
276 MockDownloadItemFactory::~MockDownloadItemFactory() {} 280 MockDownloadItemFactory::~MockDownloadItemFactory() {}
277 281
278 MockDownloadItemImpl* MockDownloadItemFactory::GetItem(int id) { 282 MockDownloadItemImpl* MockDownloadItemFactory::GetItem(int id) {
279 if (items_.find(id) == items_.end()) 283 if (items_.find(id) == items_.end())
280 return NULL; 284 return NULL;
281 return items_[id]; 285 return items_[id];
282 } 286 }
283 287
284 MockDownloadItemImpl* MockDownloadItemFactory::PopItem() { 288 MockDownloadItemImpl* MockDownloadItemFactory::PopItem() {
285 if (items_.empty()) 289 if (items_.empty())
286 return NULL; 290 return NULL;
287 291
288 std::map<uint32, MockDownloadItemImpl*>::iterator first_item 292 std::map<uint32_t, MockDownloadItemImpl*>::iterator first_item =
289 = items_.begin(); 293 items_.begin();
290 MockDownloadItemImpl* result = first_item->second; 294 MockDownloadItemImpl* result = first_item->second;
291 items_.erase(first_item); 295 items_.erase(first_item);
292 return result; 296 return result;
293 } 297 }
294 298
295 void MockDownloadItemFactory::RemoveItem(int id) { 299 void MockDownloadItemFactory::RemoveItem(int id) {
296 DCHECK(items_.find(id) != items_.end()); 300 DCHECK(items_.find(id) != items_.end());
297 items_.erase(id); 301 items_.erase(id);
298 } 302 }
299 303
300 DownloadItemImpl* MockDownloadItemFactory::CreatePersistedItem( 304 DownloadItemImpl* MockDownloadItemFactory::CreatePersistedItem(
301 DownloadItemImplDelegate* delegate, 305 DownloadItemImplDelegate* delegate,
302 uint32 download_id, 306 uint32_t download_id,
303 const base::FilePath& current_path, 307 const base::FilePath& current_path,
304 const base::FilePath& target_path, 308 const base::FilePath& target_path,
305 const std::vector<GURL>& url_chain, 309 const std::vector<GURL>& url_chain,
306 const GURL& referrer_url, 310 const GURL& referrer_url,
307 const std::string& mime_type, 311 const std::string& mime_type,
308 const std::string& original_mime_type, 312 const std::string& original_mime_type,
309 const base::Time& start_time, 313 const base::Time& start_time,
310 const base::Time& end_time, 314 const base::Time& end_time,
311 const std::string& etag, 315 const std::string& etag,
312 const std::string& last_modified, 316 const std::string& last_modified,
313 int64 received_bytes, 317 int64_t received_bytes,
314 int64 total_bytes, 318 int64_t total_bytes,
315 DownloadItem::DownloadState state, 319 DownloadItem::DownloadState state,
316 DownloadDangerType danger_type, 320 DownloadDangerType danger_type,
317 DownloadInterruptReason interrupt_reason, 321 DownloadInterruptReason interrupt_reason,
318 bool opened, 322 bool opened,
319 const net::BoundNetLog& bound_net_log) { 323 const net::BoundNetLog& bound_net_log) {
320 DCHECK(items_.find(download_id) == items_.end()); 324 DCHECK(items_.find(download_id) == items_.end());
321 MockDownloadItemImpl* result = 325 MockDownloadItemImpl* result =
322 new StrictMock<MockDownloadItemImpl>(&item_delegate_); 326 new StrictMock<MockDownloadItemImpl>(&item_delegate_);
323 EXPECT_CALL(*result, GetId()) 327 EXPECT_CALL(*result, GetId())
324 .WillRepeatedly(Return(download_id)); 328 .WillRepeatedly(Return(download_id));
325 items_[download_id] = result; 329 items_[download_id] = result;
326 return result; 330 return result;
327 } 331 }
328 332
329 DownloadItemImpl* MockDownloadItemFactory::CreateActiveItem( 333 DownloadItemImpl* MockDownloadItemFactory::CreateActiveItem(
330 DownloadItemImplDelegate* delegate, 334 DownloadItemImplDelegate* delegate,
331 uint32 download_id, 335 uint32_t download_id,
332 const DownloadCreateInfo& info, 336 const DownloadCreateInfo& info,
333 const net::BoundNetLog& bound_net_log) { 337 const net::BoundNetLog& bound_net_log) {
334 DCHECK(items_.find(download_id) == items_.end()); 338 DCHECK(items_.find(download_id) == items_.end());
335 339
336 MockDownloadItemImpl* result = 340 MockDownloadItemImpl* result =
337 new StrictMock<MockDownloadItemImpl>(&item_delegate_); 341 new StrictMock<MockDownloadItemImpl>(&item_delegate_);
338 EXPECT_CALL(*result, GetId()) 342 EXPECT_CALL(*result, GetId())
339 .WillRepeatedly(Return(download_id)); 343 .WillRepeatedly(Return(download_id));
340 items_[download_id] = result; 344 items_[download_id] = result;
341 345
342 // Active items are created and then immediately are called to start 346 // Active items are created and then immediately are called to start
343 // the download. 347 // the download.
344 EXPECT_CALL(*result, MockStart(_, _)); 348 EXPECT_CALL(*result, MockStart(_, _));
345 349
346 return result; 350 return result;
347 } 351 }
348 352
349 DownloadItemImpl* MockDownloadItemFactory::CreateSavePageItem( 353 DownloadItemImpl* MockDownloadItemFactory::CreateSavePageItem(
350 DownloadItemImplDelegate* delegate, 354 DownloadItemImplDelegate* delegate,
351 uint32 download_id, 355 uint32_t download_id,
352 const base::FilePath& path, 356 const base::FilePath& path,
353 const GURL& url, 357 const GURL& url,
354 const std::string& mime_type, 358 const std::string& mime_type,
355 scoped_ptr<DownloadRequestHandleInterface> request_handle, 359 scoped_ptr<DownloadRequestHandleInterface> request_handle,
356 const net::BoundNetLog& bound_net_log) { 360 const net::BoundNetLog& bound_net_log) {
357 DCHECK(items_.find(download_id) == items_.end()); 361 DCHECK(items_.find(download_id) == items_.end());
358 362
359 MockDownloadItemImpl* result = 363 MockDownloadItemImpl* result =
360 new StrictMock<MockDownloadItemImpl>(&item_delegate_); 364 new StrictMock<MockDownloadItemImpl>(&item_delegate_);
361 EXPECT_CALL(*result, GetId()) 365 EXPECT_CALL(*result, GetId())
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 } 434 }
431 }; 435 };
432 436
433 class MockDownloadManagerObserver : public DownloadManager::Observer { 437 class MockDownloadManagerObserver : public DownloadManager::Observer {
434 public: 438 public:
435 MockDownloadManagerObserver() {} 439 MockDownloadManagerObserver() {}
436 ~MockDownloadManagerObserver() {} 440 ~MockDownloadManagerObserver() {}
437 MOCK_METHOD2(OnDownloadCreated, void( 441 MOCK_METHOD2(OnDownloadCreated, void(
438 DownloadManager*, DownloadItem*)); 442 DownloadManager*, DownloadItem*));
439 MOCK_METHOD1(ManagerGoingDown, void(DownloadManager*)); 443 MOCK_METHOD1(ManagerGoingDown, void(DownloadManager*));
440 MOCK_METHOD2(SelectFileDialogDisplayed, void( 444 MOCK_METHOD2(SelectFileDialogDisplayed, void(DownloadManager*, int32_t));
441 DownloadManager*, int32));
442 }; 445 };
443 446
444 } // namespace 447 } // namespace
445 448
446 class DownloadManagerTest : public testing::Test { 449 class DownloadManagerTest : public testing::Test {
447 public: 450 public:
448 static const char* kTestData; 451 static const char* kTestData;
449 static const size_t kTestDataLen; 452 static const size_t kTestDataLen;
450 453
451 DownloadManagerTest() 454 DownloadManagerTest()
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 mock_browser_context_.reset(); 513 mock_browser_context_.reset();
511 download_urls_.clear(); 514 download_urls_.clear();
512 } 515 }
513 516
514 // Returns download id. 517 // Returns download id.
515 MockDownloadItemImpl& AddItemToManager() { 518 MockDownloadItemImpl& AddItemToManager() {
516 DownloadCreateInfo info; 519 DownloadCreateInfo info;
517 520
518 // Args are ignored except for download id, so everything else can be 521 // Args are ignored except for download id, so everything else can be
519 // null. 522 // null.
520 uint32 id = next_download_id_; 523 uint32_t id = next_download_id_;
521 ++next_download_id_; 524 ++next_download_id_;
522 info.request_handle.reset(new DownloadRequestHandle); 525 info.request_handle.reset(new DownloadRequestHandle);
523 download_manager_->CreateActiveItem(id, info); 526 download_manager_->CreateActiveItem(id, info);
524 DCHECK(mock_download_item_factory_->GetItem(id)); 527 DCHECK(mock_download_item_factory_->GetItem(id));
525 MockDownloadItemImpl& item(*mock_download_item_factory_->GetItem(id)); 528 MockDownloadItemImpl& item(*mock_download_item_factory_->GetItem(id));
526 // Satisfy expectation. If the item is created in StartDownload(), 529 // Satisfy expectation. If the item is created in StartDownload(),
527 // we call Start on it immediately, so we need to set that expectation 530 // we call Start on it immediately, so we need to set that expectation
528 // in the factory. 531 // in the factory.
529 scoped_ptr<DownloadRequestHandleInterface> req_handle; 532 scoped_ptr<DownloadRequestHandleInterface> req_handle;
530 item.Start(scoped_ptr<DownloadFile>(), req_handle.Pass()); 533 item.Start(scoped_ptr<DownloadFile>(), req_handle.Pass());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 std::vector<GURL> download_urls_; 591 std::vector<GURL> download_urls_;
589 592
590 private: 593 private:
591 base::MessageLoopForUI message_loop_; 594 base::MessageLoopForUI message_loop_;
592 TestBrowserThread ui_thread_; 595 TestBrowserThread ui_thread_;
593 TestBrowserThread file_thread_; 596 TestBrowserThread file_thread_;
594 base::WeakPtr<MockDownloadItemFactory> mock_download_item_factory_; 597 base::WeakPtr<MockDownloadItemFactory> mock_download_item_factory_;
595 scoped_ptr<MockDownloadManagerDelegate> mock_download_manager_delegate_; 598 scoped_ptr<MockDownloadManagerDelegate> mock_download_manager_delegate_;
596 scoped_ptr<MockBrowserContext> mock_browser_context_; 599 scoped_ptr<MockBrowserContext> mock_browser_context_;
597 scoped_ptr<MockDownloadManagerObserver> observer_; 600 scoped_ptr<MockDownloadManagerObserver> observer_;
598 uint32 next_download_id_; 601 uint32_t next_download_id_;
599 602
600 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); 603 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest);
601 }; 604 };
602 605
603 // Confirm the appropriate invocations occur when you start a download. 606 // Confirm the appropriate invocations occur when you start a download.
604 TEST_F(DownloadManagerTest, StartDownload) { 607 TEST_F(DownloadManagerTest, StartDownload) {
605 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo); 608 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo);
606 scoped_ptr<ByteStreamReader> stream; 609 scoped_ptr<ByteStreamReader> stream;
607 uint32 local_id(5); // Random value 610 uint32_t local_id(5); // Random value
608 base::FilePath download_path(FILE_PATH_LITERAL("download/path")); 611 base::FilePath download_path(FILE_PATH_LITERAL("download/path"));
609 612
610 EXPECT_FALSE(download_manager_->GetDownload(local_id)); 613 EXPECT_FALSE(download_manager_->GetDownload(local_id));
611 614
612 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) 615 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _))
613 .WillOnce(Return()); 616 .WillOnce(Return());
614 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId(_)) 617 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId(_))
615 .WillOnce(RunCallback<0>(local_id)); 618 .WillOnce(RunCallback<0>(local_id));
616 619
617 // Doing nothing will set the default download directory to null. 620 // Doing nothing will set the default download directory to null.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 EXPECT_TRUE(callback_called_); 669 EXPECT_TRUE(callback_called_);
667 EXPECT_EQ(path, target_path_); 670 EXPECT_EQ(path, target_path_);
668 EXPECT_EQ(DownloadItem::TARGET_DISPOSITION_OVERWRITE, target_disposition_); 671 EXPECT_EQ(DownloadItem::TARGET_DISPOSITION_OVERWRITE, target_disposition_);
669 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, danger_type_); 672 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, danger_type_);
670 EXPECT_EQ(path, intermediate_path_); 673 EXPECT_EQ(path, intermediate_path_);
671 } 674 }
672 675
673 // Confirm the DownloadManagerImpl::RemoveAllDownloads() functionality 676 // Confirm the DownloadManagerImpl::RemoveAllDownloads() functionality
674 TEST_F(DownloadManagerTest, RemoveAllDownloads) { 677 TEST_F(DownloadManagerTest, RemoveAllDownloads) {
675 base::Time now(base::Time::Now()); 678 base::Time now(base::Time::Now());
676 for (uint32 i = 0; i < 4; ++i) { 679 for (uint32_t i = 0; i < 4; ++i) {
677 MockDownloadItemImpl& item(AddItemToManager()); 680 MockDownloadItemImpl& item(AddItemToManager());
678 EXPECT_EQ(i, item.GetId()); 681 EXPECT_EQ(i, item.GetId());
679 EXPECT_CALL(item, GetStartTime()) 682 EXPECT_CALL(item, GetStartTime())
680 .WillRepeatedly(Return(now)); 683 .WillRepeatedly(Return(now));
681 } 684 }
682 685
683 // Specify states for each. 686 // Specify states for each.
684 EXPECT_CALL(GetMockDownloadItem(0), GetState()) 687 EXPECT_CALL(GetMockDownloadItem(0), GetState())
685 .WillRepeatedly(Return(DownloadItem::COMPLETE)); 688 .WillRepeatedly(Return(DownloadItem::COMPLETE));
686 EXPECT_CALL(GetMockDownloadItem(1), GetState()) 689 EXPECT_CALL(GetMockDownloadItem(1), GetState())
(...skipping 14 matching lines...) Expand all
701 .Times(0); 704 .Times(0);
702 705
703 download_manager_->RemoveAllDownloads(); 706 download_manager_->RemoveAllDownloads();
704 // Because we're mocking the download item, the Remove call doesn't 707 // Because we're mocking the download item, the Remove call doesn't
705 // result in them being removed from the DownloadManager list. 708 // result in them being removed from the DownloadManager list.
706 } 709 }
707 710
708 // Confirm that only downloads with same origin are removed. 711 // Confirm that only downloads with same origin are removed.
709 TEST_F(DownloadManagerTest, RemoveSameOriginDownloads) { 712 TEST_F(DownloadManagerTest, RemoveSameOriginDownloads) {
710 base::Time now(base::Time::Now()); 713 base::Time now(base::Time::Now());
711 for (uint32 i = 0; i < 2; ++i) { 714 for (uint32_t i = 0; i < 2; ++i) {
712 MockDownloadItemImpl& item(AddItemToManager()); 715 MockDownloadItemImpl& item(AddItemToManager());
713 EXPECT_CALL(item, GetStartTime()).WillRepeatedly(Return(now)); 716 EXPECT_CALL(item, GetStartTime()).WillRepeatedly(Return(now));
714 EXPECT_CALL(item, GetState()) 717 EXPECT_CALL(item, GetState())
715 .WillRepeatedly(Return(DownloadItem::COMPLETE)); 718 .WillRepeatedly(Return(DownloadItem::COMPLETE));
716 } 719 }
717 720
718 EXPECT_CALL(GetMockDownloadItem(0), Remove()); 721 EXPECT_CALL(GetMockDownloadItem(0), Remove());
719 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0); 722 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0);
720 723
721 url::Origin origin_to_clear(download_urls_[0]); 724 url::Origin origin_to_clear(download_urls_[0]);
722 int remove_count = download_manager_->RemoveDownloadsByOriginAndTime( 725 int remove_count = download_manager_->RemoveDownloadsByOriginAndTime(
723 origin_to_clear, base::Time(), base::Time::Max()); 726 origin_to_clear, base::Time(), base::Time::Max());
724 EXPECT_EQ(remove_count, 1); 727 EXPECT_EQ(remove_count, 1);
725 } 728 }
726 729
727 } // namespace content 730 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_manager_impl.cc ('k') | content/browser/download/download_net_log_parameters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698