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

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

Issue 1518093002: Cleanup DownloadItemImpl unittests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup-download-item
Patch Set: Catch up with upstream Created 5 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
« no previous file with comments | « no previous file | no next file » | 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 "base/callback.h" 5 #include "base/callback.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 #include "content/browser/byte_stream.h" 10 #include "content/browser/byte_stream.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 class MockRequestHandle : public DownloadRequestHandleInterface { 86 class MockRequestHandle : public DownloadRequestHandleInterface {
87 public: 87 public:
88 MOCK_CONST_METHOD0(GetWebContents, WebContents*()); 88 MOCK_CONST_METHOD0(GetWebContents, WebContents*());
89 MOCK_CONST_METHOD0(GetDownloadManager, DownloadManager*()); 89 MOCK_CONST_METHOD0(GetDownloadManager, DownloadManager*());
90 MOCK_CONST_METHOD0(PauseRequest, void()); 90 MOCK_CONST_METHOD0(PauseRequest, void());
91 MOCK_CONST_METHOD0(ResumeRequest, void()); 91 MOCK_CONST_METHOD0(ResumeRequest, void());
92 MOCK_CONST_METHOD0(CancelRequest, void()); 92 MOCK_CONST_METHOD0(CancelRequest, void());
93 MOCK_CONST_METHOD0(DebugString, std::string()); 93 MOCK_CONST_METHOD0(DebugString, std::string());
94 }; 94 };
95 95
96 // Schedules a task to invoke the RenameCompletionCallback with |new_path| on 96 class TestDownloadItemObserver : public DownloadItem::Observer {
97 // the UI thread. Should only be used as the action for
98 // MockDownloadFile::Rename as follows:
99 // EXPECT_CALL(download_file, Rename*(_,_))
100 // .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE,
101 // new_path));
102 ACTION_P2(ScheduleRenameCallback, interrupt_reason, new_path) {
103 BrowserThread::PostTask(
104 BrowserThread::UI, FROM_HERE,
105 base::Bind(arg1, interrupt_reason, new_path));
106 }
107
108 } // namespace
109
110 class DownloadItemTest : public testing::Test {
111 public: 97 public:
112 class MockObserver : public DownloadItem::Observer { 98 explicit TestDownloadItemObserver(DownloadItem* item)
113 public:
114 explicit MockObserver(DownloadItem* item)
115 : item_(item), 99 : item_(item),
116 last_state_(item->GetState()), 100 last_state_(item->GetState()),
117 removed_(false), 101 removed_(false),
118 destroyed_(false), 102 destroyed_(false),
119 updated_(false), 103 updated_(false),
120 interrupt_count_(0), 104 interrupt_count_(0),
121 resume_count_(0) { 105 resume_count_(0) {
122 item_->AddObserver(this); 106 item_->AddObserver(this);
107 }
108
109 ~TestDownloadItemObserver() override {
110 if (item_)
111 item_->RemoveObserver(this);
112 }
113
114 bool download_removed() const { return removed_; }
115 bool download_destroyed() const { return destroyed_; }
116 int interrupt_count() const { return interrupt_count_; }
117 int resume_count() const { return resume_count_; }
118
119 bool CheckAndResetDownloadUpdated() {
120 bool was_updated = updated_;
121 updated_ = false;
122 return was_updated;
123 }
124
125 private:
126 void OnDownloadRemoved(DownloadItem* download) override {
127 DVLOG(20) << " " << __FUNCTION__
128 << " download = " << download->DebugString(false);
129 removed_ = true;
130 }
131
132 void OnDownloadUpdated(DownloadItem* download) override {
133 DVLOG(20) << " " << __FUNCTION__
134 << " download = " << download->DebugString(false);
135 updated_ = true;
136 DownloadItem::DownloadState new_state = download->GetState();
137 if (last_state_ == DownloadItem::IN_PROGRESS &&
138 new_state == DownloadItem::INTERRUPTED) {
139 interrupt_count_++;
123 } 140 }
141 if (last_state_ == DownloadItem::INTERRUPTED &&
142 new_state == DownloadItem::IN_PROGRESS) {
143 resume_count_++;
144 }
145 last_state_ = new_state;
146 }
124 147
125 ~MockObserver() override { 148 void OnDownloadOpened(DownloadItem* download) override {
126 if (item_) item_->RemoveObserver(this); 149 DVLOG(20) << " " << __FUNCTION__
127 } 150 << " download = " << download->DebugString(false);
151 }
128 152
129 void OnDownloadRemoved(DownloadItem* download) override { 153 void OnDownloadDestroyed(DownloadItem* download) override {
130 DVLOG(20) << " " << __FUNCTION__ 154 DVLOG(20) << " " << __FUNCTION__
131 << " download = " << download->DebugString(false); 155 << " download = " << download->DebugString(false);
132 removed_ = true; 156 destroyed_ = true;
133 } 157 item_->RemoveObserver(this);
158 item_ = NULL;
159 }
134 160
135 void OnDownloadUpdated(DownloadItem* download) override { 161 DownloadItem* item_;
136 DVLOG(20) << " " << __FUNCTION__ 162 DownloadItem::DownloadState last_state_;
137 << " download = " << download->DebugString(false); 163 bool removed_;
138 updated_ = true; 164 bool destroyed_;
139 DownloadItem::DownloadState new_state = download->GetState(); 165 bool updated_;
140 if (last_state_ == DownloadItem::IN_PROGRESS && 166 int interrupt_count_;
141 new_state == DownloadItem::INTERRUPTED) { 167 int resume_count_;
142 interrupt_count_++; 168 };
143 }
144 if (last_state_ == DownloadItem::INTERRUPTED &&
145 new_state == DownloadItem::IN_PROGRESS) {
146 resume_count_++;
147 }
148 last_state_ = new_state;
149 }
150 169
151 void OnDownloadOpened(DownloadItem* download) override { 170 // Schedules a task to invoke the RenameCompletionCallback with |new_path| on
152 DVLOG(20) << " " << __FUNCTION__ 171 // the UI thread. Should only be used as the action for
153 << " download = " << download->DebugString(false); 172 // MockDownloadFile::Rename as follows:
154 } 173 // EXPECT_CALL(download_file, Rename*(_,_))
174 // .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE,
175 // new_path));
176 ACTION_P2(ScheduleRenameCallback, interrupt_reason, new_path) {
177 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
178 base::Bind(arg1, interrupt_reason, new_path));
179 }
155 180
156 void OnDownloadDestroyed(DownloadItem* download) override { 181 } // namespace
157 DVLOG(20) << " " << __FUNCTION__
158 << " download = " << download->DebugString(false);
159 destroyed_ = true;
160 item_->RemoveObserver(this);
161 item_ = NULL;
162 }
163 182
164 bool CheckRemoved() { 183 class DownloadItemTest : public testing::Test {
165 return removed_; 184 public:
166 }
167
168 bool CheckDestroyed() {
169 return destroyed_;
170 }
171
172 bool CheckUpdated() {
173 bool was_updated = updated_;
174 updated_ = false;
175 return was_updated;
176 }
177
178 int GetInterruptCount() {
179 return interrupt_count_;
180 }
181
182 int GetResumeCount() {
183 return resume_count_;
184 }
185
186 private:
187 DownloadItem* item_;
188 DownloadItem::DownloadState last_state_;
189 bool removed_;
190 bool destroyed_;
191 bool updated_;
192 int interrupt_count_;
193 int resume_count_;
194 };
195
196 DownloadItemTest() 185 DownloadItemTest()
197 : ui_thread_(BrowserThread::UI, &loop_), 186 : ui_thread_(BrowserThread::UI, &loop_),
198 file_thread_(BrowserThread::FILE, &loop_), 187 file_thread_(BrowserThread::FILE, &loop_),
199 delegate_() { 188 delegate_() {
200 } 189 }
201 190
202 ~DownloadItemTest() { 191 ~DownloadItemTest() {
203 } 192 }
204 193
205 virtual void SetUp() { 194 virtual void SetUp() {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // Tests to ensure calls that change a DownloadItem generate an update to 322 // Tests to ensure calls that change a DownloadItem generate an update to
334 // observers. 323 // observers.
335 // State changing functions not tested: 324 // State changing functions not tested:
336 // void OpenDownload(); 325 // void OpenDownload();
337 // void ShowDownloadInShell(); 326 // void ShowDownloadInShell();
338 // void CompleteDelayedDownload(); 327 // void CompleteDelayedDownload();
339 // set_* mutators 328 // set_* mutators
340 329
341 TEST_F(DownloadItemTest, NotificationAfterUpdate) { 330 TEST_F(DownloadItemTest, NotificationAfterUpdate) {
342 DownloadItemImpl* item = CreateDownloadItem(); 331 DownloadItemImpl* item = CreateDownloadItem();
343 MockObserver observer(item); 332 TestDownloadItemObserver observer(item);
344 333
345 item->DestinationUpdate(kDownloadChunkSize, kDownloadSpeed, std::string()); 334 item->DestinationUpdate(kDownloadChunkSize, kDownloadSpeed, std::string());
346 ASSERT_TRUE(observer.CheckUpdated()); 335 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
347 EXPECT_EQ(kDownloadSpeed, item->CurrentSpeed()); 336 EXPECT_EQ(kDownloadSpeed, item->CurrentSpeed());
348 } 337 }
349 338
350 TEST_F(DownloadItemTest, NotificationAfterCancel) { 339 TEST_F(DownloadItemTest, NotificationAfterCancel) {
351 DownloadItemImpl* user_cancel = CreateDownloadItem(); 340 DownloadItemImpl* user_cancel = CreateDownloadItem();
352 MockDownloadFile* download_file = 341 MockDownloadFile* download_file =
353 AddDownloadFileToDownloadItem(user_cancel, NULL); 342 AddDownloadFileToDownloadItem(user_cancel, NULL);
354 EXPECT_CALL(*download_file, Cancel()); 343 EXPECT_CALL(*download_file, Cancel());
355 MockObserver observer1(user_cancel); 344 TestDownloadItemObserver observer1(user_cancel);
356 345
357 user_cancel->Cancel(true); 346 user_cancel->Cancel(true);
358 ASSERT_TRUE(observer1.CheckUpdated()); 347 ASSERT_TRUE(observer1.CheckAndResetDownloadUpdated());
359 348
360 DownloadItemImpl* system_cancel = CreateDownloadItem(); 349 DownloadItemImpl* system_cancel = CreateDownloadItem();
361 download_file = AddDownloadFileToDownloadItem(system_cancel, NULL); 350 download_file = AddDownloadFileToDownloadItem(system_cancel, NULL);
362 EXPECT_CALL(*download_file, Cancel()); 351 EXPECT_CALL(*download_file, Cancel());
363 MockObserver observer2(system_cancel); 352 TestDownloadItemObserver observer2(system_cancel);
364 353
365 system_cancel->Cancel(false); 354 system_cancel->Cancel(false);
366 ASSERT_TRUE(observer2.CheckUpdated()); 355 ASSERT_TRUE(observer2.CheckAndResetDownloadUpdated());
367 } 356 }
368 357
369 TEST_F(DownloadItemTest, NotificationAfterComplete) { 358 TEST_F(DownloadItemTest, NotificationAfterComplete) {
370 DownloadItemImpl* item = CreateDownloadItem(); 359 DownloadItemImpl* item = CreateDownloadItem();
371 MockObserver observer(item); 360 TestDownloadItemObserver observer(item);
372 361
373 item->OnAllDataSaved(DownloadItem::kEmptyFileHash); 362 item->OnAllDataSaved(DownloadItem::kEmptyFileHash);
374 ASSERT_TRUE(observer.CheckUpdated()); 363 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
375 364
376 item->MarkAsComplete(); 365 item->MarkAsComplete();
377 ASSERT_TRUE(observer.CheckUpdated()); 366 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
378 } 367 }
379 368
380 TEST_F(DownloadItemTest, NotificationAfterDownloadedFileRemoved) { 369 TEST_F(DownloadItemTest, NotificationAfterDownloadedFileRemoved) {
381 DownloadItemImpl* item = CreateDownloadItem(); 370 DownloadItemImpl* item = CreateDownloadItem();
382 MockObserver observer(item); 371 TestDownloadItemObserver observer(item);
383 372
384 item->OnDownloadedFileRemoved(); 373 item->OnDownloadedFileRemoved();
385 ASSERT_TRUE(observer.CheckUpdated()); 374 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
386 } 375 }
387 376
388 TEST_F(DownloadItemTest, NotificationAfterInterrupted) { 377 TEST_F(DownloadItemTest, NotificationAfterInterrupted) {
389 DownloadItemImpl* item = CreateDownloadItem(); 378 DownloadItemImpl* item = CreateDownloadItem();
390 MockDownloadFile* download_file = 379 MockDownloadFile* download_file =
391 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 380 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
392 EXPECT_CALL(*download_file, Cancel()); 381 EXPECT_CALL(*download_file, Cancel());
393 MockObserver observer(item); 382 TestDownloadItemObserver observer(item);
394 383
395 EXPECT_CALL(*mock_delegate(), MockResumeInterruptedDownload(_,_)) 384 EXPECT_CALL(*mock_delegate(), MockResumeInterruptedDownload(_,_))
396 .Times(0); 385 .Times(0);
397 386
398 item->DestinationObserverAsWeakPtr()->DestinationError( 387 item->DestinationObserverAsWeakPtr()->DestinationError(
399 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); 388 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED);
400 ASSERT_TRUE(observer.CheckUpdated()); 389 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
401 } 390 }
402 391
403 TEST_F(DownloadItemTest, NotificationAfterDestroyed) { 392 TEST_F(DownloadItemTest, NotificationAfterDestroyed) {
404 DownloadItemImpl* item = CreateDownloadItem(); 393 DownloadItemImpl* item = CreateDownloadItem();
405 MockObserver observer(item); 394 TestDownloadItemObserver observer(item);
406 395
407 DestroyDownloadItem(item); 396 DestroyDownloadItem(item);
408 ASSERT_TRUE(observer.CheckDestroyed()); 397 ASSERT_TRUE(observer.download_destroyed());
409 } 398 }
410 399
411 TEST_F(DownloadItemTest, ContinueAfterInterrupted) { 400 TEST_F(DownloadItemTest, ContinueAfterInterrupted) {
412 base::CommandLine::ForCurrentProcess()->AppendSwitch( 401 base::CommandLine::ForCurrentProcess()->AppendSwitch(
413 switches::kEnableDownloadResumption); 402 switches::kEnableDownloadResumption);
414 403
415 TestBrowserContext test_browser_context; 404 TestBrowserContext test_browser_context;
416 DownloadItemImpl* item = CreateDownloadItem(); 405 DownloadItemImpl* item = CreateDownloadItem();
417 MockObserver observer(item); 406 TestDownloadItemObserver observer(item);
418 DownloadItemImplDelegate::DownloadTargetCallback callback; 407 DownloadItemImplDelegate::DownloadTargetCallback callback;
419 MockDownloadFile* download_file = 408 MockDownloadFile* download_file =
420 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 409 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
421 410
422 // Interrupt the download, using a continuable interrupt. 411 // Interrupt the download, using a continuable interrupt.
423 EXPECT_CALL(*download_file, FullPath()) 412 EXPECT_CALL(*download_file, FullPath())
424 .WillOnce(Return(base::FilePath())); 413 .WillOnce(Return(base::FilePath()));
425 EXPECT_CALL(*download_file, Detach()); 414 EXPECT_CALL(*download_file, Detach());
426 EXPECT_CALL(*mock_delegate(), GetBrowserContext()) 415 EXPECT_CALL(*mock_delegate(), GetBrowserContext())
427 .WillRepeatedly(Return(&test_browser_context)); 416 .WillRepeatedly(Return(&test_browser_context));
428 EXPECT_CALL(*mock_delegate(), MockResumeInterruptedDownload(_, _)).Times(1); 417 EXPECT_CALL(*mock_delegate(), MockResumeInterruptedDownload(_, _)).Times(1);
429 item->DestinationObserverAsWeakPtr()->DestinationError( 418 item->DestinationObserverAsWeakPtr()->DestinationError(
430 DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR); 419 DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR);
431 ASSERT_TRUE(observer.CheckUpdated()); 420 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
432 ASSERT_EQ(1, observer.GetInterruptCount()); 421 ASSERT_EQ(1, observer.interrupt_count());
433 422
434 // Test expectations verify that ResumeInterruptedDownload() is called (by way 423 // Test expectations verify that ResumeInterruptedDownload() is called (by way
435 // of MockResumeInterruptedDownload) after the download is interrupted. But 424 // of MockResumeInterruptedDownload) after the download is interrupted. But
436 // the mock doesn't follow through with the resumption. 425 // the mock doesn't follow through with the resumption.
437 // ResumeInterruptedDownload() being called is sufficient for verifying that 426 // ResumeInterruptedDownload() being called is sufficient for verifying that
438 // the automatic resumption was triggered. 427 // the automatic resumption was triggered.
439 RunAllPendingInMessageLoops(); 428 RunAllPendingInMessageLoops();
440 429
441 CleanupItem(item, download_file, DownloadItem::INTERRUPTED); 430 CleanupItem(item, download_file, DownloadItem::INTERRUPTED);
442 } 431 }
443 432
444 // Same as above, but with a non-continuable interrupt. 433 // Same as above, but with a non-continuable interrupt.
445 TEST_F(DownloadItemTest, RestartAfterInterrupted) { 434 TEST_F(DownloadItemTest, RestartAfterInterrupted) {
446 base::CommandLine::ForCurrentProcess()->AppendSwitch( 435 base::CommandLine::ForCurrentProcess()->AppendSwitch(
447 switches::kEnableDownloadResumption); 436 switches::kEnableDownloadResumption);
448 437
449 DownloadItemImpl* item = CreateDownloadItem(); 438 DownloadItemImpl* item = CreateDownloadItem();
450 MockObserver observer(item); 439 TestDownloadItemObserver observer(item);
451 DownloadItemImplDelegate::DownloadTargetCallback callback; 440 DownloadItemImplDelegate::DownloadTargetCallback callback;
452 MockDownloadFile* download_file = 441 MockDownloadFile* download_file =
453 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 442 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
454 443
455 // Interrupt the download, using a restartable interrupt. 444 // Interrupt the download, using a restartable interrupt.
456 EXPECT_CALL(*download_file, Cancel()); 445 EXPECT_CALL(*download_file, Cancel());
457 item->DestinationObserverAsWeakPtr()->DestinationError( 446 item->DestinationObserverAsWeakPtr()->DestinationError(
458 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); 447 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED);
459 ASSERT_TRUE(observer.CheckUpdated()); 448 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
460 // Should not try to auto-resume. 449 // Should not try to auto-resume.
461 ASSERT_EQ(1, observer.GetInterruptCount()); 450 ASSERT_EQ(1, observer.interrupt_count());
462 ASSERT_EQ(0, observer.GetResumeCount()); 451 ASSERT_EQ(0, observer.resume_count());
463 RunAllPendingInMessageLoops(); 452 RunAllPendingInMessageLoops();
464 453
465 CleanupItem(item, download_file, DownloadItem::INTERRUPTED); 454 CleanupItem(item, download_file, DownloadItem::INTERRUPTED);
466 } 455 }
467 456
468 // Check we do correct cleanup for RESUME_MODE_INVALID interrupts. 457 // Check we do correct cleanup for RESUME_MODE_INVALID interrupts.
469 TEST_F(DownloadItemTest, UnresumableInterrupt) { 458 TEST_F(DownloadItemTest, UnresumableInterrupt) {
470 base::CommandLine::ForCurrentProcess()->AppendSwitch( 459 base::CommandLine::ForCurrentProcess()->AppendSwitch(
471 switches::kEnableDownloadResumption); 460 switches::kEnableDownloadResumption);
472 461
473 DownloadItemImpl* item = CreateDownloadItem(); 462 DownloadItemImpl* item = CreateDownloadItem();
474 MockObserver observer(item); 463 TestDownloadItemObserver observer(item);
475 DownloadItemImplDelegate::DownloadTargetCallback callback; 464 DownloadItemImplDelegate::DownloadTargetCallback callback;
476 MockDownloadFile* download_file = 465 MockDownloadFile* download_file =
477 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 466 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
478 467
479 // Fail final rename with unresumable reason. 468 // Fail final rename with unresumable reason.
480 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) 469 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _))
481 .WillOnce(Return(true)); 470 .WillOnce(Return(true));
482 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) 471 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _))
483 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED, 472 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED,
484 base::FilePath(kDummyPath))); 473 base::FilePath(kDummyPath)));
485 EXPECT_CALL(*download_file, Cancel()); 474 EXPECT_CALL(*download_file, Cancel());
486 475
487 // Complete download to trigger final rename. 476 // Complete download to trigger final rename.
488 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); 477 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string());
489 RunAllPendingInMessageLoops(); 478 RunAllPendingInMessageLoops();
490 479
491 ASSERT_TRUE(observer.CheckUpdated()); 480 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
492 // Should not try to auto-resume. 481 // Should not try to auto-resume.
493 ASSERT_EQ(1, observer.GetInterruptCount()); 482 ASSERT_EQ(1, observer.interrupt_count());
494 ASSERT_EQ(0, observer.GetResumeCount()); 483 ASSERT_EQ(0, observer.resume_count());
495 484
496 CleanupItem(item, download_file, DownloadItem::INTERRUPTED); 485 CleanupItem(item, download_file, DownloadItem::INTERRUPTED);
497 } 486 }
498 487
499 TEST_F(DownloadItemTest, LimitRestartsAfterInterrupted) { 488 TEST_F(DownloadItemTest, LimitRestartsAfterInterrupted) {
500 base::CommandLine::ForCurrentProcess()->AppendSwitch( 489 base::CommandLine::ForCurrentProcess()->AppendSwitch(
501 switches::kEnableDownloadResumption); 490 switches::kEnableDownloadResumption);
502 491
503 TestBrowserContext test_browser_context; 492 TestBrowserContext test_browser_context;
504 DownloadItemImpl* item = CreateDownloadItem(); 493 DownloadItemImpl* item = CreateDownloadItem();
505 base::WeakPtr<DownloadDestinationObserver> as_observer( 494 base::WeakPtr<DownloadDestinationObserver> as_observer(
506 item->DestinationObserverAsWeakPtr()); 495 item->DestinationObserverAsWeakPtr());
507 MockObserver observer(item); 496 TestDownloadItemObserver observer(item);
508 MockDownloadFile* mock_download_file(NULL); 497 MockDownloadFile* mock_download_file(NULL);
509 scoped_ptr<DownloadFile> download_file; 498 scoped_ptr<DownloadFile> download_file;
510 MockRequestHandle* mock_request_handle(NULL); 499 MockRequestHandle* mock_request_handle(NULL);
511 scoped_ptr<DownloadRequestHandleInterface> request_handle; 500 scoped_ptr<DownloadRequestHandleInterface> request_handle;
512 DownloadItemImplDelegate::DownloadTargetCallback callback; 501 DownloadItemImplDelegate::DownloadTargetCallback callback;
513 502
514 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _)) 503 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _))
515 .WillRepeatedly(SaveArg<1>(&callback)); 504 .WillRepeatedly(SaveArg<1>(&callback));
516 EXPECT_CALL(*mock_delegate(), GetBrowserContext()) 505 EXPECT_CALL(*mock_delegate(), GetBrowserContext())
517 .WillRepeatedly(Return(&test_browser_context)); 506 .WillRepeatedly(Return(&test_browser_context));
(...skipping 19 matching lines...) Expand all
537 base::FilePath target_path(kDummyPath); 526 base::FilePath target_path(kDummyPath);
538 base::FilePath intermediate_path( 527 base::FilePath intermediate_path(
539 target_path.InsertBeforeExtensionASCII("x")); 528 target_path.InsertBeforeExtensionASCII("x"));
540 EXPECT_CALL(*mock_download_file, RenameAndUniquify(intermediate_path, _)) 529 EXPECT_CALL(*mock_download_file, RenameAndUniquify(intermediate_path, _))
541 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, 530 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE,
542 intermediate_path)); 531 intermediate_path));
543 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, 532 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE,
544 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); 533 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path);
545 RunAllPendingInMessageLoops(); 534 RunAllPendingInMessageLoops();
546 } 535 }
547 ASSERT_EQ(i, observer.GetResumeCount()); 536 ASSERT_EQ(i, observer.resume_count());
548 537
549 // Use a continuable interrupt. 538 // Use a continuable interrupt.
550 item->DestinationObserverAsWeakPtr()->DestinationError( 539 item->DestinationObserverAsWeakPtr()->DestinationError(
551 DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR); 540 DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR);
552 541
553 ASSERT_EQ(i + 1, observer.GetInterruptCount()); 542 ASSERT_EQ(i + 1, observer.interrupt_count());
554 ::testing::Mock::VerifyAndClearExpectations(mock_download_file); 543 ::testing::Mock::VerifyAndClearExpectations(mock_download_file);
555 } 544 }
556 545
557 CleanupItem(item, mock_download_file, DownloadItem::INTERRUPTED); 546 CleanupItem(item, mock_download_file, DownloadItem::INTERRUPTED);
558 } 547 }
559 548
560 TEST_F(DownloadItemTest, NotificationAfterRemove) { 549 TEST_F(DownloadItemTest, NotificationAfterRemove) {
561 DownloadItemImpl* item = CreateDownloadItem(); 550 DownloadItemImpl* item = CreateDownloadItem();
562 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item, NULL); 551 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item, NULL);
563 EXPECT_CALL(*download_file, Cancel()); 552 EXPECT_CALL(*download_file, Cancel());
564 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); 553 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_));
565 MockObserver observer(item); 554 TestDownloadItemObserver observer(item);
566 555
567 item->Remove(); 556 item->Remove();
568 ASSERT_TRUE(observer.CheckUpdated()); 557 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
569 ASSERT_TRUE(observer.CheckRemoved()); 558 ASSERT_TRUE(observer.download_removed());
570 } 559 }
571 560
572 TEST_F(DownloadItemTest, NotificationAfterOnContentCheckCompleted) { 561 TEST_F(DownloadItemTest, NotificationAfterOnContentCheckCompleted) {
573 // Setting to NOT_DANGEROUS does not trigger a notification. 562 // Setting to NOT_DANGEROUS does not trigger a notification.
574 DownloadItemImpl* safe_item = CreateDownloadItem(); 563 DownloadItemImpl* safe_item = CreateDownloadItem();
575 MockObserver safe_observer(safe_item); 564 TestDownloadItemObserver safe_observer(safe_item);
576 565
577 safe_item->OnAllDataSaved(std::string()); 566 safe_item->OnAllDataSaved(std::string());
578 EXPECT_TRUE(safe_observer.CheckUpdated()); 567 EXPECT_TRUE(safe_observer.CheckAndResetDownloadUpdated());
579 safe_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 568 safe_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
580 EXPECT_TRUE(safe_observer.CheckUpdated()); 569 EXPECT_TRUE(safe_observer.CheckAndResetDownloadUpdated());
581 570
582 // Setting to unsafe url or unsafe file should trigger a notification. 571 // Setting to unsafe url or unsafe file should trigger a notification.
583 DownloadItemImpl* unsafeurl_item = 572 DownloadItemImpl* unsafeurl_item =
584 CreateDownloadItem(); 573 CreateDownloadItem();
585 MockObserver unsafeurl_observer(unsafeurl_item); 574 TestDownloadItemObserver unsafeurl_observer(unsafeurl_item);
586 575
587 unsafeurl_item->OnAllDataSaved(std::string()); 576 unsafeurl_item->OnAllDataSaved(std::string());
588 EXPECT_TRUE(unsafeurl_observer.CheckUpdated()); 577 EXPECT_TRUE(unsafeurl_observer.CheckAndResetDownloadUpdated());
589 unsafeurl_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_DANGEROUS_URL); 578 unsafeurl_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_DANGEROUS_URL);
590 EXPECT_TRUE(unsafeurl_observer.CheckUpdated()); 579 EXPECT_TRUE(unsafeurl_observer.CheckAndResetDownloadUpdated());
591 580
592 unsafeurl_item->ValidateDangerousDownload(); 581 unsafeurl_item->ValidateDangerousDownload();
593 EXPECT_TRUE(unsafeurl_observer.CheckUpdated()); 582 EXPECT_TRUE(unsafeurl_observer.CheckAndResetDownloadUpdated());
594 583
595 DownloadItemImpl* unsafefile_item = 584 DownloadItemImpl* unsafefile_item =
596 CreateDownloadItem(); 585 CreateDownloadItem();
597 MockObserver unsafefile_observer(unsafefile_item); 586 TestDownloadItemObserver unsafefile_observer(unsafefile_item);
598 587
599 unsafefile_item->OnAllDataSaved(std::string()); 588 unsafefile_item->OnAllDataSaved(std::string());
600 EXPECT_TRUE(unsafefile_observer.CheckUpdated()); 589 EXPECT_TRUE(unsafefile_observer.CheckAndResetDownloadUpdated());
601 unsafefile_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); 590 unsafefile_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
602 EXPECT_TRUE(unsafefile_observer.CheckUpdated()); 591 EXPECT_TRUE(unsafefile_observer.CheckAndResetDownloadUpdated());
603 592
604 unsafefile_item->ValidateDangerousDownload(); 593 unsafefile_item->ValidateDangerousDownload();
605 EXPECT_TRUE(unsafefile_observer.CheckUpdated()); 594 EXPECT_TRUE(unsafefile_observer.CheckAndResetDownloadUpdated());
606 } 595 }
607 596
608 // DownloadItemImpl::OnDownloadTargetDetermined will schedule a task to run 597 // DownloadItemImpl::OnDownloadTargetDetermined will schedule a task to run
609 // DownloadFile::Rename(). Once the rename 598 // DownloadFile::Rename(). Once the rename
610 // completes, DownloadItemImpl receives a notification with the new file 599 // completes, DownloadItemImpl receives a notification with the new file
611 // name. Check that observers are updated when the new filename is available and 600 // name. Check that observers are updated when the new filename is available and
612 // not before. 601 // not before.
613 TEST_F(DownloadItemTest, NotificationAfterOnDownloadTargetDetermined) { 602 TEST_F(DownloadItemTest, NotificationAfterOnDownloadTargetDetermined) {
614 DownloadItemImpl* item = CreateDownloadItem(); 603 DownloadItemImpl* item = CreateDownloadItem();
615 DownloadItemImplDelegate::DownloadTargetCallback callback; 604 DownloadItemImplDelegate::DownloadTargetCallback callback;
616 MockDownloadFile* download_file = 605 MockDownloadFile* download_file =
617 AddDownloadFileToDownloadItem(item, &callback); 606 AddDownloadFileToDownloadItem(item, &callback);
618 MockObserver observer(item); 607 TestDownloadItemObserver observer(item);
619 base::FilePath target_path(kDummyPath); 608 base::FilePath target_path(kDummyPath);
620 base::FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x")); 609 base::FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x"));
621 base::FilePath new_intermediate_path( 610 base::FilePath new_intermediate_path(
622 target_path.InsertBeforeExtensionASCII("y")); 611 target_path.InsertBeforeExtensionASCII("y"));
623 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) 612 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _))
624 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, 613 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE,
625 new_intermediate_path)); 614 new_intermediate_path));
626 615
627 // Currently, a notification would be generated if the danger type is anything 616 // Currently, a notification would be generated if the danger type is anything
628 // other than NOT_DANGEROUS. 617 // other than NOT_DANGEROUS.
629 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, 618 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE,
630 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); 619 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path);
631 EXPECT_FALSE(observer.CheckUpdated()); 620 EXPECT_FALSE(observer.CheckAndResetDownloadUpdated());
632 RunAllPendingInMessageLoops(); 621 RunAllPendingInMessageLoops();
633 EXPECT_TRUE(observer.CheckUpdated()); 622 EXPECT_TRUE(observer.CheckAndResetDownloadUpdated());
634 EXPECT_EQ(new_intermediate_path, item->GetFullPath()); 623 EXPECT_EQ(new_intermediate_path, item->GetFullPath());
635 624
636 CleanupItem(item, download_file, DownloadItem::IN_PROGRESS); 625 CleanupItem(item, download_file, DownloadItem::IN_PROGRESS);
637 } 626 }
638 627
639 TEST_F(DownloadItemTest, NotificationAfterTogglePause) { 628 TEST_F(DownloadItemTest, NotificationAfterTogglePause) {
640 DownloadItemImpl* item = CreateDownloadItem(); 629 DownloadItemImpl* item = CreateDownloadItem();
641 MockObserver observer(item); 630 TestDownloadItemObserver observer(item);
642 MockDownloadFile* mock_download_file(new MockDownloadFile); 631 MockDownloadFile* mock_download_file(new MockDownloadFile);
643 scoped_ptr<DownloadFile> download_file(mock_download_file); 632 scoped_ptr<DownloadFile> download_file(mock_download_file);
644 scoped_ptr<DownloadRequestHandleInterface> request_handle( 633 scoped_ptr<DownloadRequestHandleInterface> request_handle(
645 new NiceMock<MockRequestHandle>); 634 new NiceMock<MockRequestHandle>);
646 635
647 EXPECT_CALL(*mock_download_file, Initialize(_)); 636 EXPECT_CALL(*mock_download_file, Initialize(_));
648 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(_, _)); 637 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(_, _));
649 item->Start(download_file.Pass(), request_handle.Pass()); 638 item->Start(download_file.Pass(), request_handle.Pass());
650 639
651 item->Pause(); 640 item->Pause();
652 ASSERT_TRUE(observer.CheckUpdated()); 641 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
653 642
654 ASSERT_TRUE(item->IsPaused()); 643 ASSERT_TRUE(item->IsPaused());
655 644
656 item->Resume(); 645 item->Resume();
657 ASSERT_TRUE(observer.CheckUpdated()); 646 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
658 647
659 RunAllPendingInMessageLoops(); 648 RunAllPendingInMessageLoops();
660 649
661 CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS); 650 CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS);
662 } 651 }
663 652
664 TEST_F(DownloadItemTest, DisplayName) { 653 TEST_F(DownloadItemTest, DisplayName) {
665 DownloadItemImpl* item = CreateDownloadItem(); 654 DownloadItemImpl* item = CreateDownloadItem();
666 DownloadItemImplDelegate::DownloadTargetCallback callback; 655 DownloadItemImplDelegate::DownloadTargetCallback callback;
667 MockDownloadFile* download_file = 656 MockDownloadFile* download_file =
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 887
899 EXPECT_FALSE(item->GetFileExternallyRemoved()); 888 EXPECT_FALSE(item->GetFileExternallyRemoved());
900 item->OnDownloadedFileRemoved(); 889 item->OnDownloadedFileRemoved();
901 EXPECT_TRUE(item->GetFileExternallyRemoved()); 890 EXPECT_TRUE(item->GetFileExternallyRemoved());
902 } 891 }
903 892
904 TEST_F(DownloadItemTest, DestinationUpdate) { 893 TEST_F(DownloadItemTest, DestinationUpdate) {
905 DownloadItemImpl* item = CreateDownloadItem(); 894 DownloadItemImpl* item = CreateDownloadItem();
906 base::WeakPtr<DownloadDestinationObserver> as_observer( 895 base::WeakPtr<DownloadDestinationObserver> as_observer(
907 item->DestinationObserverAsWeakPtr()); 896 item->DestinationObserverAsWeakPtr());
908 MockObserver observer(item); 897 TestDownloadItemObserver observer(item);
909 898
910 EXPECT_EQ(0l, item->CurrentSpeed()); 899 EXPECT_EQ(0l, item->CurrentSpeed());
911 EXPECT_EQ("", item->GetHashState()); 900 EXPECT_EQ("", item->GetHashState());
912 EXPECT_EQ(0l, item->GetReceivedBytes()); 901 EXPECT_EQ(0l, item->GetReceivedBytes());
913 EXPECT_EQ(0l, item->GetTotalBytes()); 902 EXPECT_EQ(0l, item->GetTotalBytes());
914 EXPECT_FALSE(observer.CheckUpdated()); 903 EXPECT_FALSE(observer.CheckAndResetDownloadUpdated());
915 item->SetTotalBytes(100l); 904 item->SetTotalBytes(100l);
916 EXPECT_EQ(100l, item->GetTotalBytes()); 905 EXPECT_EQ(100l, item->GetTotalBytes());
917 906
918 as_observer->DestinationUpdate(10, 20, "deadbeef"); 907 as_observer->DestinationUpdate(10, 20, "deadbeef");
919 EXPECT_EQ(20l, item->CurrentSpeed()); 908 EXPECT_EQ(20l, item->CurrentSpeed());
920 EXPECT_EQ("deadbeef", item->GetHashState()); 909 EXPECT_EQ("deadbeef", item->GetHashState());
921 EXPECT_EQ(10l, item->GetReceivedBytes()); 910 EXPECT_EQ(10l, item->GetReceivedBytes());
922 EXPECT_EQ(100l, item->GetTotalBytes()); 911 EXPECT_EQ(100l, item->GetTotalBytes());
923 EXPECT_TRUE(observer.CheckUpdated()); 912 EXPECT_TRUE(observer.CheckAndResetDownloadUpdated());
924 913
925 as_observer->DestinationUpdate(200, 20, "livebeef"); 914 as_observer->DestinationUpdate(200, 20, "livebeef");
926 EXPECT_EQ(20l, item->CurrentSpeed()); 915 EXPECT_EQ(20l, item->CurrentSpeed());
927 EXPECT_EQ("livebeef", item->GetHashState()); 916 EXPECT_EQ("livebeef", item->GetHashState());
928 EXPECT_EQ(200l, item->GetReceivedBytes()); 917 EXPECT_EQ(200l, item->GetReceivedBytes());
929 EXPECT_EQ(0l, item->GetTotalBytes()); 918 EXPECT_EQ(0l, item->GetTotalBytes());
930 EXPECT_TRUE(observer.CheckUpdated()); 919 EXPECT_TRUE(observer.CheckAndResetDownloadUpdated());
931 } 920 }
932 921
933 TEST_F(DownloadItemTest, DestinationError) { 922 TEST_F(DownloadItemTest, DestinationError) {
934 DownloadItemImpl* item = CreateDownloadItem(); 923 DownloadItemImpl* item = CreateDownloadItem();
935 MockDownloadFile* download_file = 924 MockDownloadFile* download_file =
936 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 925 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
937 base::WeakPtr<DownloadDestinationObserver> as_observer( 926 base::WeakPtr<DownloadDestinationObserver> as_observer(
938 item->DestinationObserverAsWeakPtr()); 927 item->DestinationObserverAsWeakPtr());
939 MockObserver observer(item); 928 TestDownloadItemObserver observer(item);
940 929
941 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 930 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
942 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, item->GetLastReason()); 931 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NONE, item->GetLastReason());
943 EXPECT_FALSE(observer.CheckUpdated()); 932 EXPECT_FALSE(observer.CheckAndResetDownloadUpdated());
944 933
945 EXPECT_CALL(*download_file, Cancel()); 934 EXPECT_CALL(*download_file, Cancel());
946 as_observer->DestinationError( 935 as_observer->DestinationError(
947 DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED); 936 DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED);
948 mock_delegate()->VerifyAndClearExpectations(); 937 mock_delegate()->VerifyAndClearExpectations();
949 EXPECT_TRUE(observer.CheckUpdated()); 938 EXPECT_TRUE(observer.CheckAndResetDownloadUpdated());
950 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); 939 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState());
951 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED, 940 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED,
952 item->GetLastReason()); 941 item->GetLastReason());
953 } 942 }
954 943
955 TEST_F(DownloadItemTest, DestinationCompleted) { 944 TEST_F(DownloadItemTest, DestinationCompleted) {
956 DownloadItemImpl* item = CreateDownloadItem(); 945 DownloadItemImpl* item = CreateDownloadItem();
957 base::WeakPtr<DownloadDestinationObserver> as_observer( 946 base::WeakPtr<DownloadDestinationObserver> as_observer(
958 item->DestinationObserverAsWeakPtr()); 947 item->DestinationObserverAsWeakPtr());
959 MockObserver observer(item); 948 TestDownloadItemObserver observer(item);
960 949
961 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 950 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
962 EXPECT_EQ("", item->GetHash()); 951 EXPECT_EQ("", item->GetHash());
963 EXPECT_EQ("", item->GetHashState()); 952 EXPECT_EQ("", item->GetHashState());
964 EXPECT_FALSE(item->AllDataSaved()); 953 EXPECT_FALSE(item->AllDataSaved());
965 EXPECT_FALSE(observer.CheckUpdated()); 954 EXPECT_FALSE(observer.CheckAndResetDownloadUpdated());
966 955
967 as_observer->DestinationUpdate(10, 20, "deadbeef"); 956 as_observer->DestinationUpdate(10, 20, "deadbeef");
968 EXPECT_TRUE(observer.CheckUpdated()); 957 EXPECT_TRUE(observer.CheckAndResetDownloadUpdated());
969 EXPECT_FALSE(observer.CheckUpdated()); // Confirm reset. 958 EXPECT_FALSE(observer.CheckAndResetDownloadUpdated()); // Confirm reset.
970 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 959 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
971 EXPECT_EQ("", item->GetHash()); 960 EXPECT_EQ("", item->GetHash());
972 EXPECT_EQ("deadbeef", item->GetHashState()); 961 EXPECT_EQ("deadbeef", item->GetHashState());
973 EXPECT_FALSE(item->AllDataSaved()); 962 EXPECT_FALSE(item->AllDataSaved());
974 963
975 as_observer->DestinationCompleted("livebeef"); 964 as_observer->DestinationCompleted("livebeef");
976 mock_delegate()->VerifyAndClearExpectations(); 965 mock_delegate()->VerifyAndClearExpectations();
977 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 966 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
978 EXPECT_TRUE(observer.CheckUpdated()); 967 EXPECT_TRUE(observer.CheckAndResetDownloadUpdated());
979 EXPECT_EQ("livebeef", item->GetHash()); 968 EXPECT_EQ("livebeef", item->GetHash());
980 EXPECT_EQ("", item->GetHashState()); 969 EXPECT_EQ("", item->GetHashState());
981 EXPECT_TRUE(item->AllDataSaved()); 970 EXPECT_TRUE(item->AllDataSaved());
982 } 971 }
983 972
984 TEST_F(DownloadItemTest, EnabledActionsForNormalDownload) { 973 TEST_F(DownloadItemTest, EnabledActionsForNormalDownload) {
985 DownloadItemImpl* item = CreateDownloadItem(); 974 DownloadItemImpl* item = CreateDownloadItem();
986 MockDownloadFile* download_file = 975 MockDownloadFile* download_file =
987 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 976 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
988 977
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 base::Unretained(&returned_path))); 1285 base::Unretained(&returned_path)));
1297 RunAllPendingInMessageLoops(); 1286 RunAllPendingInMessageLoops();
1298 EXPECT_TRUE(returned_path.empty()); 1287 EXPECT_TRUE(returned_path.empty());
1299 } 1288 }
1300 1289
1301 TEST(MockDownloadItem, Compiles) { 1290 TEST(MockDownloadItem, Compiles) {
1302 MockDownloadItem mock_item; 1291 MockDownloadItem mock_item;
1303 } 1292 }
1304 1293
1305 } // namespace content 1294 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698