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

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

Issue 11363222: Persist download interrupt reason, both target and current paths, and url_chain. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changed ordering of target_path and current_path everywhere to match that of DownloadItemImpl. Created 8 years 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 | Annotate | Revision Log
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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 63
64 class MockDownloadItemImpl : public DownloadItemImpl { 64 class MockDownloadItemImpl : public DownloadItemImpl {
65 public: 65 public:
66 // Use history constructor for minimal base object. 66 // Use history constructor for minimal base object.
67 MockDownloadItemImpl(DownloadItemImplDelegate* delegate) 67 MockDownloadItemImpl(DownloadItemImplDelegate* delegate)
68 : DownloadItemImpl( 68 : DownloadItemImpl(
69 delegate, 69 delegate,
70 content::DownloadId(), 70 content::DownloadId(),
71 FilePath(), 71 FilePath(),
72 GURL(), 72 FilePath(),
73 std::vector<GURL>(),
73 GURL(), 74 GURL(),
74 base::Time(), 75 base::Time(),
75 base::Time(), 76 base::Time(),
76 0, 77 0,
77 0, 78 0,
78 DownloadItem::IN_PROGRESS, 79 DownloadItem::IN_PROGRESS,
80 DOWNLOAD_INTERRUPT_REASON_NONE,
79 false, 81 false,
80 net::BoundNetLog()) {} 82 net::BoundNetLog()) {}
81 virtual ~MockDownloadItemImpl() {} 83 virtual ~MockDownloadItemImpl() {}
82 84
83 MOCK_METHOD4(OnDownloadTargetDetermined, 85 MOCK_METHOD4(OnDownloadTargetDetermined,
84 void(const FilePath&, TargetDisposition, 86 void(const FilePath&, TargetDisposition,
85 DownloadDangerType, const FilePath&)); 87 DownloadDangerType, const FilePath&));
86 MOCK_METHOD1(AddObserver, void(DownloadItem::Observer*)); 88 MOCK_METHOD1(AddObserver, void(DownloadItem::Observer*));
87 MOCK_METHOD1(RemoveObserver, void(DownloadItem::Observer*)); 89 MOCK_METHOD1(RemoveObserver, void(DownloadItem::Observer*));
88 MOCK_METHOD0(UpdateObservers, void()); 90 MOCK_METHOD0(UpdateObservers, void());
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 MockDownloadItemImpl* PopItem(); 219 MockDownloadItemImpl* PopItem();
218 220
219 // Should be called when the item of this id is removed so that 221 // Should be called when the item of this id is removed so that
220 // we don't keep dangling pointers. 222 // we don't keep dangling pointers.
221 void RemoveItem(int id); 223 void RemoveItem(int id);
222 224
223 // Overridden methods from DownloadItemFactory. 225 // Overridden methods from DownloadItemFactory.
224 virtual DownloadItemImpl* CreatePersistedItem( 226 virtual DownloadItemImpl* CreatePersistedItem(
225 DownloadItemImplDelegate* delegate, 227 DownloadItemImplDelegate* delegate,
226 DownloadId download_id, 228 DownloadId download_id,
227 const FilePath& path, 229 const FilePath& current_path,
228 const GURL& url, 230 const FilePath& target_path,
231 const std::vector<GURL>& url_chain,
229 const GURL& referrer_url, 232 const GURL& referrer_url,
230 const base::Time& start_time, 233 const base::Time& start_time,
231 const base::Time& end_time, 234 const base::Time& end_time,
232 int64 received_bytes, 235 int64 received_bytes,
233 int64 total_bytes, 236 int64 total_bytes,
234 DownloadItem::DownloadState state, 237 DownloadItem::DownloadState state,
238 DownloadInterruptReason interrupt_reason,
235 bool opened, 239 bool opened,
236 const net::BoundNetLog& bound_net_log) OVERRIDE; 240 const net::BoundNetLog& bound_net_log) OVERRIDE;
237 virtual DownloadItemImpl* CreateActiveItem( 241 virtual DownloadItemImpl* CreateActiveItem(
238 DownloadItemImplDelegate* delegate, 242 DownloadItemImplDelegate* delegate,
239 const DownloadCreateInfo& info, 243 const DownloadCreateInfo& info,
240 scoped_ptr<DownloadRequestHandleInterface> request_handle, 244 scoped_ptr<DownloadRequestHandleInterface> request_handle,
241 const net::BoundNetLog& bound_net_log) OVERRIDE; 245 const net::BoundNetLog& bound_net_log) OVERRIDE;
242 virtual DownloadItemImpl* CreateSavePageItem( 246 virtual DownloadItemImpl* CreateSavePageItem(
243 DownloadItemImplDelegate* delegate, 247 DownloadItemImplDelegate* delegate,
244 const FilePath& path, 248 const FilePath& path,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 } 280 }
277 281
278 void MockDownloadItemFactory::RemoveItem(int id) { 282 void MockDownloadItemFactory::RemoveItem(int id) {
279 DCHECK(items_.find(id) != items_.end()); 283 DCHECK(items_.find(id) != items_.end());
280 items_.erase(id); 284 items_.erase(id);
281 } 285 }
282 286
283 DownloadItemImpl* MockDownloadItemFactory::CreatePersistedItem( 287 DownloadItemImpl* MockDownloadItemFactory::CreatePersistedItem(
284 DownloadItemImplDelegate* delegate, 288 DownloadItemImplDelegate* delegate,
285 DownloadId download_id, 289 DownloadId download_id,
286 const FilePath& path, 290 const FilePath& current_path,
287 const GURL& url, 291 const FilePath& target_path,
292 const std::vector<GURL>& url_chain,
288 const GURL& referrer_url, 293 const GURL& referrer_url,
289 const base::Time& start_time, 294 const base::Time& start_time,
290 const base::Time& end_time, 295 const base::Time& end_time,
291 int64 received_bytes, 296 int64 received_bytes,
292 int64 total_bytes, 297 int64 total_bytes,
293 DownloadItem::DownloadState state, 298 DownloadItem::DownloadState state,
299 DownloadInterruptReason interrupt_reason,
294 bool opened, 300 bool opened,
295 const net::BoundNetLog& bound_net_log) { 301 const net::BoundNetLog& bound_net_log) {
296 int local_id = download_id.local(); 302 int local_id = download_id.local();
297 DCHECK(items_.find(local_id) == items_.end()); 303 DCHECK(items_.find(local_id) == items_.end());
298 304
299 MockDownloadItemImpl* result = 305 MockDownloadItemImpl* result =
300 new StrictMock<MockDownloadItemImpl>(&item_delegate_); 306 new StrictMock<MockDownloadItemImpl>(&item_delegate_);
301 EXPECT_CALL(*result, GetId()) 307 EXPECT_CALL(*result, GetId())
302 .WillRepeatedly(Return(local_id)); 308 .WillRepeatedly(Return(local_id));
303 items_[local_id] = result; 309 items_[local_id] = result;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 DownloadCreateInfo info; 495 DownloadCreateInfo info;
490 496
491 static const char* kDownloadIdDomain = "Test download id domain"; 497 static const char* kDownloadIdDomain = "Test download id domain";
492 498
493 // Args are ignored except for download id, so everything else can be 499 // Args are ignored except for download id, so everything else can be
494 // null. 500 // null.
495 int id = next_download_id_; 501 int id = next_download_id_;
496 ++next_download_id_; 502 ++next_download_id_;
497 info.download_id = DownloadId(kDownloadIdDomain, id); 503 info.download_id = DownloadId(kDownloadIdDomain, id);
498 info.request_handle = DownloadRequestHandle(); 504 info.request_handle = DownloadRequestHandle();
499 download_manager_->CreateDownloadItem(&info, net::BoundNetLog()); 505 download_manager_->CreateDownloadItemInternal(&info, net::BoundNetLog());
500 506
501 DCHECK(mock_download_item_factory_->GetItem(id)); 507 DCHECK(mock_download_item_factory_->GetItem(id));
502 MockDownloadItemImpl& item(*mock_download_item_factory_->GetItem(id)); 508 MockDownloadItemImpl& item(*mock_download_item_factory_->GetItem(id));
503 // Satisfy expectation. If the item is created in StartDownload(), 509 // Satisfy expectation. If the item is created in StartDownload(),
504 // we call Start on it immediately, so we need to set that expectation 510 // we call Start on it immediately, so we need to set that expectation
505 // in the factory. 511 // in the factory.
506 item.Start(scoped_ptr<DownloadFile>()); 512 item.Start(scoped_ptr<DownloadFile>());
507 513
508 return item; 514 return item;
509 } 515 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 callback_called_ = false; 650 callback_called_ = false;
645 DetermineDownloadTarget(&item); 651 DetermineDownloadTarget(&item);
646 EXPECT_TRUE(callback_called_); 652 EXPECT_TRUE(callback_called_);
647 EXPECT_EQ(path, target_path_); 653 EXPECT_EQ(path, target_path_);
648 EXPECT_EQ(DownloadItem::TARGET_DISPOSITION_OVERWRITE, target_disposition_); 654 EXPECT_EQ(DownloadItem::TARGET_DISPOSITION_OVERWRITE, target_disposition_);
649 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, danger_type_); 655 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, danger_type_);
650 EXPECT_EQ(path, intermediate_path_); 656 EXPECT_EQ(path, intermediate_path_);
651 } 657 }
652 658
653 } // namespace content 659 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698