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

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

Issue 2890853002: Downloads: replace BrowserThread::FILE with task scheduler. (Closed)
Patch Set: Address Avi's comments. Created 3 years, 5 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_manager_impl.h" 5 #include "content/browser/download/download_manager_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <set> 12 #include <set>
13 #include <string> 13 #include <string>
14 #include <utility> 14 #include <utility>
15 15
16 #include "base/bind.h" 16 #include "base/bind.h"
17 #include "base/files/scoped_temp_dir.h" 17 #include "base/files/scoped_temp_dir.h"
18 #include "base/guid.h" 18 #include "base/guid.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/weak_ptr.h" 20 #include "base/memory/weak_ptr.h"
21 #include "base/message_loop/message_loop.h"
22 #include "base/run_loop.h" 21 #include "base/run_loop.h"
23 #include "base/stl_util.h" 22 #include "base/stl_util.h"
24 #include "base/strings/string16.h" 23 #include "base/strings/string16.h"
25 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
26 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
27 #include "build/build_config.h" 26 #include "build/build_config.h"
28 #include "content/browser/byte_stream.h" 27 #include "content/browser/byte_stream.h"
29 #include "content/browser/download/download_create_info.h" 28 #include "content/browser/download/download_create_info.h"
30 #include "content/browser/download/download_file_factory.h" 29 #include "content/browser/download/download_file_factory.h"
31 #include "content/browser/download/download_item_factory.h" 30 #include "content/browser/download/download_item_factory.h"
32 #include "content/browser/download/download_item_impl.h" 31 #include "content/browser/download/download_item_impl.h"
33 #include "content/browser/download/download_item_impl_delegate.h" 32 #include "content/browser/download/download_item_impl_delegate.h"
34 #include "content/browser/download/download_request_handle.h" 33 #include "content/browser/download/download_request_handle.h"
35 #include "content/browser/download/mock_download_file.h" 34 #include "content/browser/download/mock_download_file.h"
36 #include "content/browser/download/mock_download_item_impl.h" 35 #include "content/browser/download/mock_download_item_impl.h"
37 #include "content/public/browser/browser_context.h" 36 #include "content/public/browser/browser_context.h"
38 #include "content/public/browser/download_interrupt_reasons.h" 37 #include "content/public/browser/download_interrupt_reasons.h"
39 #include "content/public/browser/download_item.h" 38 #include "content/public/browser/download_item.h"
40 #include "content/public/browser/download_manager_delegate.h" 39 #include "content/public/browser/download_manager_delegate.h"
41 #include "content/public/test/mock_download_item.h" 40 #include "content/public/test/mock_download_item.h"
42 #include "content/public/test/test_browser_context.h" 41 #include "content/public/test/test_browser_context.h"
43 #include "content/public/test/test_browser_thread.h" 42 #include "content/public/test/test_browser_thread_bundle.h"
44 #include "net/log/net_log_with_source.h" 43 #include "net/log/net_log_with_source.h"
45 #include "testing/gmock/include/gmock/gmock.h" 44 #include "testing/gmock/include/gmock/gmock.h"
46 #include "testing/gmock_mutant.h" 45 #include "testing/gmock_mutant.h"
47 #include "testing/gtest/include/gtest/gtest.h" 46 #include "testing/gtest/include/gtest/gtest.h"
48 #include "url/origin.h" 47 #include "url/origin.h"
49 48
50 #if !defined(OS_ANDROID) 49 #if !defined(OS_ANDROID)
51 #include "content/public/browser/zoom_level_delegate.h" 50 #include "content/public/browser/zoom_level_delegate.h"
52 #endif // !defined(OS_ANDROID) 51 #endif // !defined(OS_ANDROID)
53 52
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 class DownloadManagerTest : public testing::Test { 381 class DownloadManagerTest : public testing::Test {
383 public: 382 public:
384 static const char* kTestData; 383 static const char* kTestData;
385 static const size_t kTestDataLen; 384 static const size_t kTestDataLen;
386 385
387 DownloadManagerTest() 386 DownloadManagerTest()
388 : callback_called_(false), 387 : callback_called_(false),
389 target_disposition_(DownloadItem::TARGET_DISPOSITION_OVERWRITE), 388 target_disposition_(DownloadItem::TARGET_DISPOSITION_OVERWRITE),
390 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), 389 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
391 interrupt_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), 390 interrupt_reason_(DOWNLOAD_INTERRUPT_REASON_NONE),
392 ui_thread_(BrowserThread::UI, &message_loop_),
393 file_thread_(BrowserThread::FILE, &message_loop_),
394 next_download_id_(0) {} 391 next_download_id_(0) {}
395 392
396 // We tear down everything in TearDown(). 393 // We tear down everything in TearDown().
397 ~DownloadManagerTest() override {} 394 ~DownloadManagerTest() override {}
398 395
399 // Create a MockDownloadItemFactory and MockDownloadManagerDelegate, 396 // Create a MockDownloadItemFactory and MockDownloadManagerDelegate,
400 // then create a DownloadManager that points 397 // then create a DownloadManager that points
401 // at all of those. 398 // at all of those.
402 void SetUp() override { 399 void SetUp() override {
403 DCHECK(!download_manager_); 400 DCHECK(!download_manager_);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 bool callback_called_; 517 bool callback_called_;
521 base::FilePath target_path_; 518 base::FilePath target_path_;
522 DownloadItem::TargetDisposition target_disposition_; 519 DownloadItem::TargetDisposition target_disposition_;
523 DownloadDangerType danger_type_; 520 DownloadDangerType danger_type_;
524 base::FilePath intermediate_path_; 521 base::FilePath intermediate_path_;
525 DownloadInterruptReason interrupt_reason_; 522 DownloadInterruptReason interrupt_reason_;
526 523
527 std::vector<GURL> download_urls_; 524 std::vector<GURL> download_urls_;
528 525
529 private: 526 private:
530 base::MessageLoopForUI message_loop_; 527 TestBrowserThreadBundle thread_bundle_;
531 TestBrowserThread ui_thread_;
532 TestBrowserThread file_thread_;
533 base::WeakPtr<MockDownloadItemFactory> mock_download_item_factory_; 528 base::WeakPtr<MockDownloadItemFactory> mock_download_item_factory_;
534 std::unique_ptr<MockDownloadManagerDelegate> mock_download_manager_delegate_; 529 std::unique_ptr<MockDownloadManagerDelegate> mock_download_manager_delegate_;
535 std::unique_ptr<MockBrowserContext> mock_browser_context_; 530 std::unique_ptr<MockBrowserContext> mock_browser_context_;
536 std::unique_ptr<MockDownloadManagerObserver> observer_; 531 std::unique_ptr<MockDownloadManagerObserver> observer_;
537 uint32_t next_download_id_; 532 uint32_t next_download_id_;
538 533
539 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); 534 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest);
540 }; 535 };
541 536
542 // Confirm the appropriate invocations occur when you start a download. 537 // Confirm the appropriate invocations occur when you start a download.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0); 651 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0);
657 652
658 base::Callback<bool(const GURL&)> url_filter = 653 base::Callback<bool(const GURL&)> url_filter =
659 GetSingleURLFilter(download_urls_[0]); 654 GetSingleURLFilter(download_urls_[0]);
660 int remove_count = download_manager_->RemoveDownloadsByURLAndTime( 655 int remove_count = download_manager_->RemoveDownloadsByURLAndTime(
661 url_filter, base::Time(), base::Time::Max()); 656 url_filter, base::Time(), base::Time::Max());
662 EXPECT_EQ(remove_count, 1); 657 EXPECT_EQ(remove_count, 1);
663 } 658 }
664 659
665 } // namespace content 660 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_manager_impl.cc ('k') | content/browser/download/download_request_core.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698