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

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

Issue 2758713002: Avoid to use the method pointer to Callback<>::Run on gmock tests (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | components/ntp_snippets/remote/remote_suggestions_provider_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_history.h" 17 #include "chrome/browser/download/download_history.h"
18 #include "chrome/browser/download/download_service_factory.h" 18 #include "chrome/browser/download/download_service_factory.h"
19 #include "chrome/browser/download/download_service_impl.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/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
27 28
28 using content::MockDownloadItem; 29 using content::MockDownloadItem;
29 using content::MockDownloadManager; 30 using content::MockDownloadManager;
30 using history::HistoryService; 31 using history::HistoryService;
31 using testing::AnyNumber; 32 using testing::AnyNumber;
32 using testing::Assign; 33 using testing::Assign;
34 using testing::CreateFunctor;
33 using testing::Return; 35 using testing::Return;
34 using testing::ReturnRefOfCopy; 36 using testing::ReturnRefOfCopy;
35 using testing::SaveArg; 37 using testing::SaveArg;
36 using testing::_; 38 using testing::_;
37 39
38 namespace { 40 namespace {
39 41
40 // A DownloadUIController::Delegate that stores the DownloadItem* for the last 42 // A DownloadUIController::Delegate that stores the DownloadItem* for the last
41 // download that was sent to the UI. 43 // download that was sent to the UI.
42 class TestDelegate : public DownloadUIController::Delegate { 44 class TestDelegate : public DownloadUIController::Delegate {
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 // DownloadHistory will immediately try to create a download using the info 336 // DownloadHistory will immediately try to create a download using the info
335 // we push through the query callback. When DownloadManager::CreateDownload 337 // we push through the query callback. When DownloadManager::CreateDownload
336 // is called, we need to first invoke the OnDownloadCreated callback for 338 // is called, we need to first invoke the OnDownloadCreated callback for
337 // DownloadHistory before returning the DownloadItem since that's the 339 // DownloadHistory before returning the DownloadItem since that's the
338 // sequence of events expected by DownloadHistory. 340 // sequence of events expected by DownloadHistory.
339 base::Closure history_on_created_callback = 341 base::Closure history_on_created_callback =
340 base::Bind(&content::DownloadManager::Observer::OnDownloadCreated, 342 base::Bind(&content::DownloadManager::Observer::OnDownloadCreated,
341 base::Unretained(download_history_manager_observer()), 343 base::Unretained(download_history_manager_observer()),
342 manager(), 344 manager(),
343 item.get()); 345 item.get());
344 EXPECT_CALL(*manager(), MockCreateDownloadItem(_)).WillOnce( 346 EXPECT_CALL(*manager(), MockCreateDownloadItem(_))
345 testing::DoAll(testing::InvokeWithoutArgs(&history_on_created_callback, 347 .WillOnce(testing::DoAll(testing::InvokeWithoutArgs(CreateFunctor(
346 &base::Closure::Run), 348 history_on_created_callback)),
347 Return(item.get()))); 349 Return(item.get())));
348 EXPECT_CALL(mock_function, Call()); 350 EXPECT_CALL(mock_function, Call());
349 351
350 history_query_callback().Run(std::move(history_downloads)); 352 history_query_callback().Run(std::move(history_downloads));
351 mock_function.Call(); 353 mock_function.Call();
352 } 354 }
353 355
354 // Now pass along the notification to the OnDownloadCreated observer from 356 // Now pass along the notification to the OnDownloadCreated observer from
355 // DownloadUIController. It should ignore the download since it's marked as 357 // DownloadUIController. It should ignore the download since it's marked as
356 // being restored from history. 358 // being restored from history.
357 ASSERT_TRUE(manager_observer()); 359 ASSERT_TRUE(manager_observer());
358 manager_observer()->OnDownloadCreated(manager(), item.get()); 360 manager_observer()->OnDownloadCreated(manager(), item.get());
359 361
360 // Finally, the expectation we've been waiting for: 362 // Finally, the expectation we've been waiting for:
361 EXPECT_FALSE(notified_item()); 363 EXPECT_FALSE(notified_item());
362 } 364 }
363 365
364 } // namespace 366 } // namespace
OLDNEW
« no previous file with comments | « no previous file | components/ntp_snippets/remote/remote_suggestions_provider_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698