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

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

Issue 10915180: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r166491 Created 8 years, 1 month 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 // This file contains download browser tests that are known to be runnable 5 // This file contains download browser tests that are known to be runnable
6 // in a pure content context. Over time tests should be migrated here. 6 // in a pure content context. Over time tests should be migrated here.
7 7
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 void DownloadFileWithDelayFactory::WaitForSomeCallback() { 263 void DownloadFileWithDelayFactory::WaitForSomeCallback() {
264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
265 265
266 if (rename_callbacks_.empty() && detach_callbacks_.empty()) { 266 if (rename_callbacks_.empty() && detach_callbacks_.empty()) {
267 waiting_ = true; 267 waiting_ = true;
268 RunMessageLoop(); 268 RunMessageLoop();
269 waiting_ = false; 269 waiting_ = false;
270 } 270 }
271 } 271 }
272 272
273 bool WasPersisted(DownloadItem* item) {
274 return item->IsPersisted();
275 }
276
277 class CountingDownloadFile : public DownloadFileImpl { 273 class CountingDownloadFile : public DownloadFileImpl {
278 public: 274 public:
279 CountingDownloadFile( 275 CountingDownloadFile(
280 scoped_ptr<DownloadSaveInfo> save_info, 276 scoped_ptr<DownloadSaveInfo> save_info,
281 const FilePath& default_downloads_directory, 277 const FilePath& default_downloads_directory,
282 const GURL& url, 278 const GURL& url,
283 const GURL& referrer_url, 279 const GURL& referrer_url,
284 bool calculate_hash, 280 bool calculate_hash,
285 scoped_ptr<ByteStreamReader> stream, 281 scoped_ptr<ByteStreamReader> stream,
286 const net::BoundNetLog& bound_net_log, 282 const net::BoundNetLog& bound_net_log,
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 // we're in the expected state. 458 // we're in the expected state.
463 scoped_ptr<DownloadTestObserver> observer(CreateInProgressWaiter(shell(), 1)); 459 scoped_ptr<DownloadTestObserver> observer(CreateInProgressWaiter(shell(), 1));
464 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); 460 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl));
465 observer->WaitForFinished(); 461 observer->WaitForFinished();
466 462
467 std::vector<DownloadItem*> downloads; 463 std::vector<DownloadItem*> downloads;
468 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); 464 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
469 ASSERT_EQ(1u, downloads.size()); 465 ASSERT_EQ(1u, downloads.size());
470 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); 466 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState());
471 467
472 // Wait for it to be persisted.
473 DownloadUpdatedObserver(
474 downloads[0], base::Bind(&WasPersisted)).WaitForEvent();
475
476 // Cancel the download and wait for download system quiesce. 468 // Cancel the download and wait for download system quiesce.
477 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); 469 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
478 scoped_refptr<DownloadTestFlushObserver> flush_observer( 470 scoped_refptr<DownloadTestFlushObserver> flush_observer(
479 new DownloadTestFlushObserver(DownloadManagerForShell(shell()))); 471 new DownloadTestFlushObserver(DownloadManagerForShell(shell())));
480 flush_observer->WaitForFlush(); 472 flush_observer->WaitForFlush();
481 473
482 // Get the important info from other threads and check it. 474 // Get the important info from other threads and check it.
483 EXPECT_TRUE(EnsureNoPendingDownloads()); 475 EXPECT_TRUE(EnsureNoPendingDownloads());
484 } 476 }
485 477
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 scoped_ptr<DownloadTestObserver> observer(CreateInProgressWaiter(shell(), 1)); 647 scoped_ptr<DownloadTestObserver> observer(CreateInProgressWaiter(shell(), 1));
656 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); 648 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl));
657 observer->WaitForFinished(); 649 observer->WaitForFinished();
658 650
659 // Get the item. 651 // Get the item.
660 std::vector<DownloadItem*> items; 652 std::vector<DownloadItem*> items;
661 DownloadManagerForShell(shell())->GetAllDownloads(&items); 653 DownloadManagerForShell(shell())->GetAllDownloads(&items);
662 ASSERT_EQ(1u, items.size()); 654 ASSERT_EQ(1u, items.size());
663 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState()); 655 EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState());
664 656
665 // Wait for it to be persisted.
666 DownloadUpdatedObserver(items[0], base::Bind(&WasPersisted)).WaitForEvent();
667
668 // Shutdown the download manager and make sure we get the right 657 // Shutdown the download manager and make sure we get the right
669 // notifications in the right order. 658 // notifications in the right order.
670 StrictMock<MockDownloadItemObserver> item_observer; 659 StrictMock<MockDownloadItemObserver> item_observer;
671 items[0]->AddObserver(&item_observer); 660 items[0]->AddObserver(&item_observer);
672 MockDownloadManagerObserver manager_observer; 661 MockDownloadManagerObserver manager_observer;
673 // Don't care about ModelChanged() events. 662 // Don't care about ModelChanged() events.
674 EXPECT_CALL(manager_observer, ModelChanged(_)) 663 EXPECT_CALL(manager_observer, ModelChanged(_))
675 .WillRepeatedly(Return()); 664 .WillRepeatedly(Return());
676 DownloadManagerForShell(shell())->AddObserver(&manager_observer); 665 DownloadManagerForShell(shell())->AddObserver(&manager_observer);
677 { 666 {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 // Shutdown the download manager. Mostly this is confirming a lack of 736 // Shutdown the download manager. Mostly this is confirming a lack of
748 // crashes. 737 // crashes.
749 DownloadManagerForShell(shell())->Shutdown(); 738 DownloadManagerForShell(shell())->Shutdown();
750 739
751 // Run the detach callback; shouldn't cause any problems. 740 // Run the detach callback; shouldn't cause any problems.
752 callbacks[0].Run(); 741 callbacks[0].Run();
753 callbacks.clear(); 742 callbacks.clear();
754 } 743 }
755 744
756 } // namespace content 745 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698