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

Side by Side Diff: chrome/browser/download/download_ui_controller_unittest.cc

Issue 2853363002: Rename the DownloadService to DownloadCoreService (Closed)
Patch Set: Created 3 years, 7 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 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 "chrome/browser/download/download_ui_controller.h" 5 #include "chrome/browser/download/download_ui_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h" 16 #include "base/observer_list.h"
17 #include "chrome/browser/download/download_core_service_factory.h"
18 #include "chrome/browser/download/download_core_service_impl.h"
17 #include "chrome/browser/download/download_history.h" 19 #include "chrome/browser/download/download_history.h"
18 #include "chrome/browser/download/download_service_factory.h"
19 #include "chrome/browser/download/download_service_impl.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 21 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
22 #include "components/history/core/browser/download_row.h" 22 #include "components/history/core/browser/download_row.h"
23 #include "content/public/test/mock_download_item.h" 23 #include "content/public/test/mock_download_item.h"
24 #include "content/public/test/mock_download_manager.h" 24 #include "content/public/test/mock_download_manager.h"
25 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gmock_mutant.h" 26 #include "testing/gmock_mutant.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 28
29 using content::MockDownloadItem; 29 using content::MockDownloadItem;
(...skipping 24 matching lines...) Expand all
54 54
55 TestDelegate::TestDelegate(base::WeakPtr<content::DownloadItem*> receiver) 55 TestDelegate::TestDelegate(base::WeakPtr<content::DownloadItem*> receiver)
56 : receiver_(receiver) { 56 : receiver_(receiver) {
57 } 57 }
58 58
59 void TestDelegate::OnNewDownloadReady(content::DownloadItem* item) { 59 void TestDelegate::OnNewDownloadReady(content::DownloadItem* item) {
60 if (receiver_.get()) 60 if (receiver_.get())
61 *receiver_ = item; 61 *receiver_ = item;
62 } 62 }
63 63
64 // A DownloadService that returns a custom DownloadHistory. 64 // A DownloadCoreService that returns a custom DownloadHistory.
65 class TestDownloadService : public DownloadServiceImpl { 65 class TestDownloadCoreService : public DownloadCoreServiceImpl {
66 public: 66 public:
67 explicit TestDownloadService(Profile* profile); 67 explicit TestDownloadCoreService(Profile* profile);
68 ~TestDownloadService() override; 68 ~TestDownloadCoreService() override;
69 69
70 void set_download_history(std::unique_ptr<DownloadHistory> download_history) { 70 void set_download_history(std::unique_ptr<DownloadHistory> download_history) {
71 download_history_.swap(download_history); 71 download_history_.swap(download_history);
72 } 72 }
73 DownloadHistory* GetDownloadHistory() override; 73 DownloadHistory* GetDownloadHistory() override;
74 74
75 private: 75 private:
76 std::unique_ptr<DownloadHistory> download_history_; 76 std::unique_ptr<DownloadHistory> download_history_;
77 }; 77 };
78 78
79 TestDownloadService::TestDownloadService(Profile* profile) 79 TestDownloadCoreService::TestDownloadCoreService(Profile* profile)
80 : DownloadServiceImpl(profile) { 80 : DownloadCoreServiceImpl(profile) {}
81 }
82 81
83 TestDownloadService::~TestDownloadService() { 82 TestDownloadCoreService::~TestDownloadCoreService() {}
84 }
85 83
86 DownloadHistory* TestDownloadService::GetDownloadHistory() { 84 DownloadHistory* TestDownloadCoreService::GetDownloadHistory() {
87 return download_history_.get(); 85 return download_history_.get();
88 } 86 }
89 87
90 // The test fixture: 88 // The test fixture:
91 class DownloadUIControllerTest : public ChromeRenderViewHostTestHarness { 89 class DownloadUIControllerTest : public ChromeRenderViewHostTestHarness {
92 public: 90 public:
93 DownloadUIControllerTest(); 91 DownloadUIControllerTest();
94 92
95 protected: 93 protected:
96 // testing::Test 94 // testing::Test
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 HistoryAdapter() : DownloadHistory::HistoryAdapter(NULL) {} 131 HistoryAdapter() : DownloadHistory::HistoryAdapter(NULL) {}
134 HistoryService::DownloadQueryCallback download_query_callback_; 132 HistoryService::DownloadQueryCallback download_query_callback_;
135 133
136 private: 134 private:
137 void QueryDownloads( 135 void QueryDownloads(
138 const HistoryService::DownloadQueryCallback& callback) override { 136 const HistoryService::DownloadQueryCallback& callback) override {
139 download_query_callback_ = callback; 137 download_query_callback_ = callback;
140 } 138 }
141 }; 139 };
142 140
143 // Constructs and returns a TestDownloadService. 141 // Constructs and returns a TestDownloadCoreService.
144 static std::unique_ptr<KeyedService> TestingDownloadServiceFactory( 142 static std::unique_ptr<KeyedService> TestingDownloadCoreServiceFactory(
145 content::BrowserContext* browser_context); 143 content::BrowserContext* browser_context);
146 144
147 std::unique_ptr<MockDownloadManager> manager_; 145 std::unique_ptr<MockDownloadManager> manager_;
148 content::DownloadManager::Observer* download_history_manager_observer_; 146 content::DownloadManager::Observer* download_history_manager_observer_;
149 content::DownloadManager::Observer* manager_observer_; 147 content::DownloadManager::Observer* manager_observer_;
150 content::DownloadItem* notified_item_; 148 content::DownloadItem* notified_item_;
151 base::WeakPtrFactory<content::DownloadItem*> notified_item_receiver_factory_; 149 base::WeakPtrFactory<content::DownloadItem*> notified_item_receiver_factory_;
152 150
153 HistoryAdapter* history_adapter_; 151 HistoryAdapter* history_adapter_;
154 }; 152 };
155 153
156 // static 154 // static
157 std::unique_ptr<KeyedService> 155 std::unique_ptr<KeyedService>
158 DownloadUIControllerTest::TestingDownloadServiceFactory( 156 DownloadUIControllerTest::TestingDownloadCoreServiceFactory(
159 content::BrowserContext* browser_context) { 157 content::BrowserContext* browser_context) {
160 return base::MakeUnique<TestDownloadService>( 158 return base::MakeUnique<TestDownloadCoreService>(
161 Profile::FromBrowserContext(browser_context)); 159 Profile::FromBrowserContext(browser_context));
162 } 160 }
163 161
164 DownloadUIControllerTest::DownloadUIControllerTest() 162 DownloadUIControllerTest::DownloadUIControllerTest()
165 : download_history_manager_observer_(NULL), 163 : download_history_manager_observer_(NULL),
166 manager_observer_(NULL), 164 manager_observer_(NULL),
167 notified_item_(NULL), 165 notified_item_(NULL),
168 notified_item_receiver_factory_(&notified_item_) { 166 notified_item_receiver_factory_(&notified_item_) {
169 } 167 }
170 168
(...skipping 17 matching lines...) Expand all
188 new DownloadHistory(manager_.get(), std::move(history_adapter))); 186 new DownloadHistory(manager_.get(), std::move(history_adapter)));
189 ASSERT_TRUE(download_history_manager_observer_); 187 ASSERT_TRUE(download_history_manager_observer_);
190 188
191 EXPECT_CALL(*manager_, AddObserver(_)) 189 EXPECT_CALL(*manager_, AddObserver(_))
192 .WillOnce(SaveArg<0>(&manager_observer_)); 190 .WillOnce(SaveArg<0>(&manager_observer_));
193 EXPECT_CALL(*manager_, 191 EXPECT_CALL(*manager_,
194 RemoveObserver(testing::Eq(testing::ByRef(manager_observer_)))) 192 RemoveObserver(testing::Eq(testing::ByRef(manager_observer_))))
195 .WillOnce(testing::Assign( 193 .WillOnce(testing::Assign(
196 &manager_observer_, 194 &manager_observer_,
197 static_cast<content::DownloadManager::Observer*>(NULL))); 195 static_cast<content::DownloadManager::Observer*>(NULL)));
198 TestDownloadService* download_service = static_cast<TestDownloadService*>( 196 TestDownloadCoreService* download_core_service =
199 DownloadServiceFactory::GetInstance()->SetTestingFactoryAndUse( 197 static_cast<TestDownloadCoreService*>(
200 browser_context(), &TestingDownloadServiceFactory)); 198 DownloadCoreServiceFactory::GetInstance()->SetTestingFactoryAndUse(
201 ASSERT_TRUE(download_service); 199 browser_context(), &TestingDownloadCoreServiceFactory));
202 download_service->set_download_history(std::move(download_history)); 200 ASSERT_TRUE(download_core_service);
201 download_core_service->set_download_history(std::move(download_history));
203 } 202 }
204 203
205 std::unique_ptr<MockDownloadItem> 204 std::unique_ptr<MockDownloadItem>
206 DownloadUIControllerTest::CreateMockInProgressDownload() { 205 DownloadUIControllerTest::CreateMockInProgressDownload() {
207 std::unique_ptr<MockDownloadItem> item( 206 std::unique_ptr<MockDownloadItem> item(
208 new testing::StrictMock<MockDownloadItem>()); 207 new testing::StrictMock<MockDownloadItem>());
209 EXPECT_CALL(*item, GetBrowserContext()) 208 EXPECT_CALL(*item, GetBrowserContext())
210 .WillRepeatedly(Return(browser_context())); 209 .WillRepeatedly(Return(browser_context()));
211 EXPECT_CALL(*item, GetId()).WillRepeatedly(Return(1)); 210 EXPECT_CALL(*item, GetId()).WillRepeatedly(Return(1));
212 EXPECT_CALL(*item, GetGuid()) 211 EXPECT_CALL(*item, GetGuid())
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 // DownloadUIController. It should ignore the download since it's marked as 357 // DownloadUIController. It should ignore the download since it's marked as
359 // being restored from history. 358 // being restored from history.
360 ASSERT_TRUE(manager_observer()); 359 ASSERT_TRUE(manager_observer());
361 manager_observer()->OnDownloadCreated(manager(), item.get()); 360 manager_observer()->OnDownloadCreated(manager(), item.get());
362 361
363 // Finally, the expectation we've been waiting for: 362 // Finally, the expectation we've been waiting for:
364 EXPECT_FALSE(notified_item()); 363 EXPECT_FALSE(notified_item());
365 } 364 }
366 365
367 } // namespace 366 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698