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

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

Issue 1551503002: Convert Pass()→std::move() in //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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"
6
7 #include <utility>
8
5 #include "base/bind.h" 9 #include "base/bind.h"
6 #include "base/callback.h" 10 #include "base/callback.h"
7 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
8 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
11 #include "base/observer_list.h" 15 #include "base/observer_list.h"
12 #include "chrome/browser/download/download_history.h" 16 #include "chrome/browser/download/download_history.h"
13 #include "chrome/browser/download/download_service_factory.h" 17 #include "chrome/browser/download/download_service_factory.h"
14 #include "chrome/browser/download/download_service_impl.h" 18 #include "chrome/browser/download/download_service_impl.h"
15 #include "chrome/browser/download/download_ui_controller.h"
16 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 20 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
18 #include "components/history/core/browser/download_row.h" 21 #include "components/history/core/browser/download_row.h"
19 #include "content/public/test/mock_download_item.h" 22 #include "content/public/test/mock_download_item.h"
20 #include "content/public/test/mock_download_manager.h" 23 #include "content/public/test/mock_download_manager.h"
21 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
23 26
24 using content::MockDownloadItem; 27 using content::MockDownloadItem;
25 using content::MockDownloadManager; 28 using content::MockDownloadManager;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 RemoveObserver(testing::Eq( 175 RemoveObserver(testing::Eq(
173 testing::ByRef(download_history_manager_observer_)))) 176 testing::ByRef(download_history_manager_observer_))))
174 .WillOnce(testing::Assign( 177 .WillOnce(testing::Assign(
175 &download_history_manager_observer_, 178 &download_history_manager_observer_,
176 static_cast<content::DownloadManager::Observer*>(NULL))); 179 static_cast<content::DownloadManager::Observer*>(NULL)));
177 EXPECT_CALL(*manager_, GetAllDownloads(_)).Times(AnyNumber()); 180 EXPECT_CALL(*manager_, GetAllDownloads(_)).Times(AnyNumber());
178 181
179 scoped_ptr<HistoryAdapter> history_adapter(new HistoryAdapter); 182 scoped_ptr<HistoryAdapter> history_adapter(new HistoryAdapter);
180 history_adapter_ = history_adapter.get(); 183 history_adapter_ = history_adapter.get();
181 scoped_ptr<DownloadHistory> download_history( 184 scoped_ptr<DownloadHistory> download_history(
182 new DownloadHistory(manager_.get(), history_adapter.Pass())); 185 new DownloadHistory(manager_.get(), std::move(history_adapter)));
183 ASSERT_TRUE(download_history_manager_observer_); 186 ASSERT_TRUE(download_history_manager_observer_);
184 187
185 EXPECT_CALL(*manager_, AddObserver(_)) 188 EXPECT_CALL(*manager_, AddObserver(_))
186 .WillOnce(SaveArg<0>(&manager_observer_)); 189 .WillOnce(SaveArg<0>(&manager_observer_));
187 EXPECT_CALL(*manager_, 190 EXPECT_CALL(*manager_,
188 RemoveObserver(testing::Eq(testing::ByRef(manager_observer_)))) 191 RemoveObserver(testing::Eq(testing::ByRef(manager_observer_))))
189 .WillOnce(testing::Assign( 192 .WillOnce(testing::Assign(
190 &manager_observer_, 193 &manager_observer_,
191 static_cast<content::DownloadManager::Observer*>(NULL))); 194 static_cast<content::DownloadManager::Observer*>(NULL)));
192 TestDownloadService* download_service = static_cast<TestDownloadService*>( 195 TestDownloadService* download_service = static_cast<TestDownloadService*>(
193 DownloadServiceFactory::GetInstance()->SetTestingFactoryAndUse( 196 DownloadServiceFactory::GetInstance()->SetTestingFactoryAndUse(
194 browser_context(), &TestingDownloadServiceFactory)); 197 browser_context(), &TestingDownloadServiceFactory));
195 ASSERT_TRUE(download_service); 198 ASSERT_TRUE(download_service);
196 download_service->set_download_history(download_history.Pass()); 199 download_service->set_download_history(std::move(download_history));
197 } 200 }
198 201
199 scoped_ptr<MockDownloadItem> 202 scoped_ptr<MockDownloadItem>
200 DownloadUIControllerTest::CreateMockInProgressDownload() { 203 DownloadUIControllerTest::CreateMockInProgressDownload() {
201 scoped_ptr<MockDownloadItem> item( 204 scoped_ptr<MockDownloadItem> item(
202 new testing::StrictMock<MockDownloadItem>()); 205 new testing::StrictMock<MockDownloadItem>());
203 EXPECT_CALL(*item, GetBrowserContext()) 206 EXPECT_CALL(*item, GetBrowserContext())
204 .WillRepeatedly(Return(browser_context())); 207 .WillRepeatedly(Return(browser_context()));
205 EXPECT_CALL(*item, GetId()).WillRepeatedly(Return(1)); 208 EXPECT_CALL(*item, GetId()).WillRepeatedly(Return(1));
206 EXPECT_CALL(*item, GetTargetFilePath()).WillRepeatedly( 209 EXPECT_CALL(*item, GetTargetFilePath()).WillRepeatedly(
(...skipping 17 matching lines...) Expand all
224 .WillRepeatedly(Return(content::DOWNLOAD_INTERRUPT_REASON_NONE)); 227 .WillRepeatedly(Return(content::DOWNLOAD_INTERRUPT_REASON_NONE));
225 EXPECT_CALL(*item, GetReceivedBytes()).WillRepeatedly(Return(0)); 228 EXPECT_CALL(*item, GetReceivedBytes()).WillRepeatedly(Return(0));
226 EXPECT_CALL(*item, GetTotalBytes()).WillRepeatedly(Return(0)); 229 EXPECT_CALL(*item, GetTotalBytes()).WillRepeatedly(Return(0));
227 EXPECT_CALL(*item, GetTargetDisposition()).WillRepeatedly( 230 EXPECT_CALL(*item, GetTargetDisposition()).WillRepeatedly(
228 Return(content::DownloadItem::TARGET_DISPOSITION_OVERWRITE)); 231 Return(content::DownloadItem::TARGET_DISPOSITION_OVERWRITE));
229 EXPECT_CALL(*item, GetOpened()).WillRepeatedly(Return(false)); 232 EXPECT_CALL(*item, GetOpened()).WillRepeatedly(Return(false));
230 EXPECT_CALL(*item, GetMimeType()).WillRepeatedly(Return(std::string())); 233 EXPECT_CALL(*item, GetMimeType()).WillRepeatedly(Return(std::string()));
231 EXPECT_CALL(*item, GetURL()).WillRepeatedly(testing::ReturnRefOfCopy(GURL())); 234 EXPECT_CALL(*item, GetURL()).WillRepeatedly(testing::ReturnRefOfCopy(GURL()));
232 EXPECT_CALL(*item, GetWebContents()).WillRepeatedly(Return(nullptr)); 235 EXPECT_CALL(*item, GetWebContents()).WillRepeatedly(Return(nullptr));
233 EXPECT_CALL(*item, IsTemporary()).WillRepeatedly(Return(false)); 236 EXPECT_CALL(*item, IsTemporary()).WillRepeatedly(Return(false));
234 return item.Pass(); 237 return item;
235 } 238 }
236 239
237 scoped_ptr<DownloadUIController::Delegate> 240 scoped_ptr<DownloadUIController::Delegate>
238 DownloadUIControllerTest::GetTestDelegate() { 241 DownloadUIControllerTest::GetTestDelegate() {
239 scoped_ptr<DownloadUIController::Delegate> delegate( 242 scoped_ptr<DownloadUIController::Delegate> delegate(
240 new TestDelegate(notified_item_receiver_factory_.GetWeakPtr())); 243 new TestDelegate(notified_item_receiver_factory_.GetWeakPtr()));
241 return delegate.Pass(); 244 return delegate;
242 } 245 }
243 246
244 // New downloads should be presented to the UI when GetTargetFilePath() returns 247 // New downloads should be presented to the UI when GetTargetFilePath() returns
245 // a non-empty path. I.e. once the download target has been determined. 248 // a non-empty path. I.e. once the download target has been determined.
246 TEST_F(DownloadUIControllerTest, DownloadUIController_NotifyBasic) { 249 TEST_F(DownloadUIControllerTest, DownloadUIController_NotifyBasic) {
247 scoped_ptr<MockDownloadItem> item(CreateMockInProgressDownload()); 250 scoped_ptr<MockDownloadItem> item(CreateMockInProgressDownload());
248 DownloadUIController controller(manager(), GetTestDelegate()); 251 DownloadUIController controller(manager(), GetTestDelegate());
249 EXPECT_CALL(*item, GetTargetFilePath()) 252 EXPECT_CALL(*item, GetTargetFilePath())
250 .WillOnce(ReturnRefOfCopy(base::FilePath())); 253 .WillOnce(ReturnRefOfCopy(base::FilePath()));
251 254
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 base::Bind(&content::DownloadManager::Observer::OnDownloadCreated, 329 base::Bind(&content::DownloadManager::Observer::OnDownloadCreated,
327 base::Unretained(download_history_manager_observer()), 330 base::Unretained(download_history_manager_observer()),
328 manager(), 331 manager(),
329 item.get()); 332 item.get());
330 EXPECT_CALL(*manager(), MockCreateDownloadItem(_)).WillOnce( 333 EXPECT_CALL(*manager(), MockCreateDownloadItem(_)).WillOnce(
331 testing::DoAll(testing::InvokeWithoutArgs(&history_on_created_callback, 334 testing::DoAll(testing::InvokeWithoutArgs(&history_on_created_callback,
332 &base::Closure::Run), 335 &base::Closure::Run),
333 Return(item.get()))); 336 Return(item.get())));
334 EXPECT_CALL(mock_function, Call()); 337 EXPECT_CALL(mock_function, Call());
335 338
336 history_query_callback().Run(history_downloads.Pass()); 339 history_query_callback().Run(std::move(history_downloads));
337 mock_function.Call(); 340 mock_function.Call();
338 } 341 }
339 342
340 // Now pass along the notification to the OnDownloadCreated observer from 343 // Now pass along the notification to the OnDownloadCreated observer from
341 // DownloadUIController. It should ignore the download since it's marked as 344 // DownloadUIController. It should ignore the download since it's marked as
342 // being restored from history. 345 // being restored from history.
343 ASSERT_TRUE(manager_observer()); 346 ASSERT_TRUE(manager_observer());
344 manager_observer()->OnDownloadCreated(manager(), item.get()); 347 manager_observer()->OnDownloadCreated(manager(), item.get());
345 348
346 // Finally, the expectation we've been waiting for: 349 // Finally, the expectation we've been waiting for:
347 EXPECT_FALSE(notified_item()); 350 EXPECT_FALSE(notified_item());
348 } 351 }
349 352
350 } // namespace 353 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698