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

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

Issue 2890853002: Downloads: replace BrowserThread::FILE with task scheduler. (Closed)
Patch Set: Add a missing mock expectation. Created 3 years, 6 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 class DownloadManagerTest : public testing::Test { 375 class DownloadManagerTest : public testing::Test {
377 public: 376 public:
378 static const char* kTestData; 377 static const char* kTestData;
379 static const size_t kTestDataLen; 378 static const size_t kTestDataLen;
380 379
381 DownloadManagerTest() 380 DownloadManagerTest()
382 : callback_called_(false), 381 : callback_called_(false),
383 target_disposition_(DownloadItem::TARGET_DISPOSITION_OVERWRITE), 382 target_disposition_(DownloadItem::TARGET_DISPOSITION_OVERWRITE),
384 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS), 383 danger_type_(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS),
385 interrupt_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), 384 interrupt_reason_(DOWNLOAD_INTERRUPT_REASON_NONE),
386 ui_thread_(BrowserThread::UI, &message_loop_),
387 file_thread_(BrowserThread::FILE, &message_loop_),
388 next_download_id_(0) {} 385 next_download_id_(0) {}
389 386
390 // We tear down everything in TearDown(). 387 // We tear down everything in TearDown().
391 ~DownloadManagerTest() override {} 388 ~DownloadManagerTest() override {}
392 389
393 // Create a MockDownloadItemFactory and MockDownloadManagerDelegate, 390 // Create a MockDownloadItemFactory and MockDownloadManagerDelegate,
394 // then create a DownloadManager that points 391 // then create a DownloadManager that points
395 // at all of those. 392 // at all of those.
396 void SetUp() override { 393 void SetUp() override {
397 DCHECK(!download_manager_); 394 DCHECK(!download_manager_);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 bool callback_called_; 511 bool callback_called_;
515 base::FilePath target_path_; 512 base::FilePath target_path_;
516 DownloadItem::TargetDisposition target_disposition_; 513 DownloadItem::TargetDisposition target_disposition_;
517 DownloadDangerType danger_type_; 514 DownloadDangerType danger_type_;
518 base::FilePath intermediate_path_; 515 base::FilePath intermediate_path_;
519 DownloadInterruptReason interrupt_reason_; 516 DownloadInterruptReason interrupt_reason_;
520 517
521 std::vector<GURL> download_urls_; 518 std::vector<GURL> download_urls_;
522 519
523 private: 520 private:
524 base::MessageLoopForUI message_loop_; 521 TestBrowserThreadBundle thread_bundle_;
525 TestBrowserThread ui_thread_;
526 TestBrowserThread file_thread_;
527 base::WeakPtr<MockDownloadItemFactory> mock_download_item_factory_; 522 base::WeakPtr<MockDownloadItemFactory> mock_download_item_factory_;
528 std::unique_ptr<MockDownloadManagerDelegate> mock_download_manager_delegate_; 523 std::unique_ptr<MockDownloadManagerDelegate> mock_download_manager_delegate_;
529 std::unique_ptr<MockBrowserContext> mock_browser_context_; 524 std::unique_ptr<MockBrowserContext> mock_browser_context_;
530 std::unique_ptr<MockDownloadManagerObserver> observer_; 525 std::unique_ptr<MockDownloadManagerObserver> observer_;
531 uint32_t next_download_id_; 526 uint32_t next_download_id_;
532 527
533 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest); 528 DISALLOW_COPY_AND_ASSIGN(DownloadManagerTest);
534 }; 529 };
535 530
536 // Confirm the appropriate invocations occur when you start a download. 531 // Confirm the appropriate invocations occur when you start a download.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0); 643 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0);
649 644
650 base::Callback<bool(const GURL&)> url_filter = 645 base::Callback<bool(const GURL&)> url_filter =
651 GetSingleURLFilter(download_urls_[0]); 646 GetSingleURLFilter(download_urls_[0]);
652 int remove_count = download_manager_->RemoveDownloadsByURLAndTime( 647 int remove_count = download_manager_->RemoveDownloadsByURLAndTime(
653 url_filter, base::Time(), base::Time::Max()); 648 url_filter, base::Time(), base::Time::Max());
654 EXPECT_EQ(remove_count, 1); 649 EXPECT_EQ(remove_count, 1);
655 } 650 }
656 651
657 } // namespace content 652 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698