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

Side by Side Diff: chrome/browser/after_startup_task_utils_unittest.cc

Issue 2122543002: Replace Closure in TaskRunner::PostTask with OneShotCallback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@07_oneshot
Patch Set: fix Created 4 years, 3 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/after_startup_task_utils.h" 5 #include "chrome/browser/after_startup_task_utils.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 12 matching lines...) Expand all
23 using content::TestBrowserThreadBundle; 23 using content::TestBrowserThreadBundle;
24 24
25 namespace { 25 namespace {
26 26
27 class WrappedTaskRunner : public base::TaskRunner { 27 class WrappedTaskRunner : public base::TaskRunner {
28 public: 28 public:
29 explicit WrappedTaskRunner(const scoped_refptr<TaskRunner>& real_runner) 29 explicit WrappedTaskRunner(const scoped_refptr<TaskRunner>& real_runner)
30 : real_task_runner_(real_runner) {} 30 : real_task_runner_(real_runner) {}
31 31
32 bool PostDelayedTask(const tracked_objects::Location& from_here, 32 bool PostDelayedTask(const tracked_objects::Location& from_here,
33 const base::Closure& task, 33 base::OnceClosure task,
34 base::TimeDelta delay) override { 34 base::TimeDelta delay) override {
35 ++posted_task_count_; 35 ++posted_task_count_;
36 return real_task_runner_->PostDelayedTask( 36 return real_task_runner_->PostDelayedTask(
37 from_here, base::Bind(&WrappedTaskRunner::RunWrappedTask, this, task), 37 from_here, base::BindOnce(&WrappedTaskRunner::RunWrappedTask, this,
38 std::move(task)),
38 base::TimeDelta()); // Squash all delays so our tests complete asap. 39 base::TimeDelta()); // Squash all delays so our tests complete asap.
39 } 40 }
40 41
41 bool RunsTasksOnCurrentThread() const override { 42 bool RunsTasksOnCurrentThread() const override {
42 return real_task_runner_->RunsTasksOnCurrentThread(); 43 return real_task_runner_->RunsTasksOnCurrentThread();
43 } 44 }
44 45
45 base::TaskRunner* real_runner() const { return real_task_runner_.get(); } 46 base::TaskRunner* real_runner() const { return real_task_runner_.get(); }
46 47
47 int total_task_count() const { return posted_task_count_ + ran_task_count_; } 48 int total_task_count() const { return posted_task_count_ + ran_task_count_; }
48 int posted_task_count() const { return posted_task_count_; } 49 int posted_task_count() const { return posted_task_count_; }
49 int ran_task_count() const { return ran_task_count_; } 50 int ran_task_count() const { return ran_task_count_; }
50 51
51 void reset_task_counts() { 52 void reset_task_counts() {
52 posted_task_count_ = 0; 53 posted_task_count_ = 0;
53 ran_task_count_ = 0; 54 ran_task_count_ = 0;
54 } 55 }
55 56
56 private: 57 private:
57 ~WrappedTaskRunner() override {} 58 ~WrappedTaskRunner() override {}
58 59
59 void RunWrappedTask(const base::Closure& task) { 60 void RunWrappedTask(base::OnceClosure task) {
60 ++ran_task_count_; 61 ++ran_task_count_;
61 task.Run(); 62 std::move(task).Run();
62 } 63 }
63 64
64 scoped_refptr<TaskRunner> real_task_runner_; 65 scoped_refptr<TaskRunner> real_task_runner_;
65 int posted_task_count_ = 0; 66 int posted_task_count_ = 0;
66 int ran_task_count_ = 0; 67 int ran_task_count_ = 0;
67 }; 68 };
68 69
69 } // namespace 70 } // namespace
70 71
71 class AfterStartupTaskTest : public testing::Test { 72 class AfterStartupTaskTest : public testing::Test {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 218
218 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting(); 219 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting();
219 EXPECT_EQ(1, db_thread_->posted_task_count()); 220 EXPECT_EQ(1, db_thread_->posted_task_count());
220 221
221 FlushDBThread(); 222 FlushDBThread();
222 RunLoop().RunUntilIdle(); 223 RunLoop().RunUntilIdle();
223 EXPECT_EQ(1, db_thread_->ran_task_count()); 224 EXPECT_EQ(1, db_thread_->ran_task_count());
224 225
225 EXPECT_EQ(0, ui_thread_->total_task_count()); 226 EXPECT_EQ(0, ui_thread_->total_task_count());
226 } 227 }
OLDNEW
« no previous file with comments | « chrome/browser/after_startup_task_utils.cc ('k') | chrome/browser/chrome_content_browser_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698