OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 using testing::SaveArg; | 30 using testing::SaveArg; |
31 using testing::_; | 31 using testing::_; |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 // A DownloadUIController::Delegate that stores the DownloadItem* for the last | 35 // A DownloadUIController::Delegate that stores the DownloadItem* for the last |
36 // download that was sent to the UI. | 36 // download that was sent to the UI. |
37 class TestDelegate : public DownloadUIController::Delegate { | 37 class TestDelegate : public DownloadUIController::Delegate { |
38 public: | 38 public: |
39 explicit TestDelegate(base::WeakPtr<content::DownloadItem*> receiver); | 39 explicit TestDelegate(base::WeakPtr<content::DownloadItem*> receiver); |
40 virtual ~TestDelegate() {} | 40 ~TestDelegate() override {} |
41 | 41 |
42 private: | 42 private: |
43 virtual void OnNewDownloadReady(content::DownloadItem* item) override; | 43 void OnNewDownloadReady(content::DownloadItem* item) override; |
44 | 44 |
45 base::WeakPtr<content::DownloadItem*> receiver_; | 45 base::WeakPtr<content::DownloadItem*> receiver_; |
46 }; | 46 }; |
47 | 47 |
48 TestDelegate::TestDelegate(base::WeakPtr<content::DownloadItem*> receiver) | 48 TestDelegate::TestDelegate(base::WeakPtr<content::DownloadItem*> receiver) |
49 : receiver_(receiver) { | 49 : receiver_(receiver) { |
50 } | 50 } |
51 | 51 |
52 void TestDelegate::OnNewDownloadReady(content::DownloadItem* item) { | 52 void TestDelegate::OnNewDownloadReady(content::DownloadItem* item) { |
53 if (receiver_.get()) | 53 if (receiver_.get()) |
54 *receiver_ = item; | 54 *receiver_ = item; |
55 } | 55 } |
56 | 56 |
57 // A DownloadService that returns a custom DownloadHistory. | 57 // A DownloadService that returns a custom DownloadHistory. |
58 class TestDownloadService : public DownloadService { | 58 class TestDownloadService : public DownloadService { |
59 public: | 59 public: |
60 explicit TestDownloadService(Profile* profile); | 60 explicit TestDownloadService(Profile* profile); |
61 virtual ~TestDownloadService(); | 61 ~TestDownloadService() override; |
62 | 62 |
63 void set_download_history(scoped_ptr<DownloadHistory> download_history) { | 63 void set_download_history(scoped_ptr<DownloadHistory> download_history) { |
64 download_history_.swap(download_history); | 64 download_history_.swap(download_history); |
65 } | 65 } |
66 virtual DownloadHistory* GetDownloadHistory() override; | 66 DownloadHistory* GetDownloadHistory() override; |
67 | 67 |
68 private: | 68 private: |
69 scoped_ptr<DownloadHistory> download_history_; | 69 scoped_ptr<DownloadHistory> download_history_; |
70 }; | 70 }; |
71 | 71 |
72 TestDownloadService::TestDownloadService(Profile* profile) | 72 TestDownloadService::TestDownloadService(Profile* profile) |
73 : DownloadService(profile) { | 73 : DownloadService(profile) { |
74 } | 74 } |
75 | 75 |
76 TestDownloadService::~TestDownloadService() { | 76 TestDownloadService::~TestDownloadService() { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 120 |
121 private: | 121 private: |
122 // A private history adapter that stores the DownloadQueryCallback when | 122 // A private history adapter that stores the DownloadQueryCallback when |
123 // QueryDownloads is called. | 123 // QueryDownloads is called. |
124 class HistoryAdapter : public DownloadHistory::HistoryAdapter { | 124 class HistoryAdapter : public DownloadHistory::HistoryAdapter { |
125 public: | 125 public: |
126 HistoryAdapter() : DownloadHistory::HistoryAdapter(NULL) {} | 126 HistoryAdapter() : DownloadHistory::HistoryAdapter(NULL) {} |
127 HistoryService::DownloadQueryCallback download_query_callback_; | 127 HistoryService::DownloadQueryCallback download_query_callback_; |
128 | 128 |
129 private: | 129 private: |
130 virtual void QueryDownloads( | 130 void QueryDownloads( |
131 const HistoryService::DownloadQueryCallback& callback) override { | 131 const HistoryService::DownloadQueryCallback& callback) override { |
132 download_query_callback_ = callback; | 132 download_query_callback_ = callback; |
133 } | 133 } |
134 }; | 134 }; |
135 | 135 |
136 // Constructs and returns a TestDownloadService. | 136 // Constructs and returns a TestDownloadService. |
137 static KeyedService* TestingDownloadServiceFactory( | 137 static KeyedService* TestingDownloadServiceFactory( |
138 content::BrowserContext* browser_context); | 138 content::BrowserContext* browser_context); |
139 | 139 |
140 scoped_ptr<MockDownloadManager> manager_; | 140 scoped_ptr<MockDownloadManager> manager_; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 // DownloadUIController. It should ignore the download since it's marked as | 337 // DownloadUIController. It should ignore the download since it's marked as |
338 // being restored from history. | 338 // being restored from history. |
339 ASSERT_TRUE(manager_observer()); | 339 ASSERT_TRUE(manager_observer()); |
340 manager_observer()->OnDownloadCreated(manager(), item.get()); | 340 manager_observer()->OnDownloadCreated(manager(), item.get()); |
341 | 341 |
342 // Finally, the expectation we've been waiting for: | 342 // Finally, the expectation we've been waiting for: |
343 EXPECT_FALSE(notified_item()); | 343 EXPECT_FALSE(notified_item()); |
344 } | 344 } |
345 | 345 |
346 } // namespace | 346 } // namespace |
OLD | NEW |