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

Side by Side Diff: base/threading/post_task_and_reply_impl_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
« no previous file with comments | « base/threading/post_task_and_reply_impl.cc ('k') | base/threading/sequenced_worker_pool.h » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/threading/post_task_and_reply_impl.h" 5 #include "base/threading/post_task_and_reply_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/test/test_simple_task_runner.h" 11 #include "base/test/test_simple_task_runner.h"
12 #include "base/threading/sequenced_task_runner_handle.h" 12 #include "base/threading/sequenced_task_runner_handle.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using ::testing::_; 16 using ::testing::_;
17 17
18 namespace base { 18 namespace base {
19 namespace internal { 19 namespace internal {
20 20
21 namespace { 21 namespace {
22 22
23 class PostTaskAndReplyTaskRunner : public internal::PostTaskAndReplyImpl { 23 class PostTaskAndReplyTaskRunner : public internal::PostTaskAndReplyImpl {
24 public: 24 public:
25 explicit PostTaskAndReplyTaskRunner(TaskRunner* destination) 25 explicit PostTaskAndReplyTaskRunner(TaskRunner* destination)
26 : destination_(destination) {} 26 : destination_(destination) {}
27 27
28 private: 28 private:
29 bool PostTask(const tracked_objects::Location& from_here, 29 bool PostTask(const tracked_objects::Location& from_here,
30 const Closure& task) override { 30 OnceClosure task) override {
31 return destination_->PostTask(from_here, task); 31 return destination_->PostTask(from_here, std::move(task));
32 } 32 }
33 33
34 // Non-owning. 34 // Non-owning.
35 TaskRunner* const destination_; 35 TaskRunner* const destination_;
36 }; 36 };
37 37
38 class ObjectToDelete : public RefCounted<ObjectToDelete> { 38 class ObjectToDelete : public RefCounted<ObjectToDelete> {
39 public: 39 public:
40 // |delete_flag| is set to true when this object is deleted 40 // |delete_flag| is set to true when this object is deleted
41 ObjectToDelete(bool* delete_flag) : delete_flag_(delete_flag) { 41 ObjectToDelete(bool* delete_flag) : delete_flag_(delete_flag) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 // Expect no reply in |reply_runner|. 91 // Expect no reply in |reply_runner|.
92 EXPECT_FALSE(reply_runner->HasPendingTask()); 92 EXPECT_FALSE(reply_runner->HasPendingTask());
93 93
94 // Expect the task to be posted to |post_runner|. 94 // Expect the task to be posted to |post_runner|.
95 EXPECT_TRUE(post_runner->HasPendingTask()); 95 EXPECT_TRUE(post_runner->HasPendingTask());
96 EXPECT_CALL(mock_object, Task(_)); 96 EXPECT_CALL(mock_object, Task(_));
97 post_runner->RunUntilIdle(); 97 post_runner->RunUntilIdle();
98 testing::Mock::VerifyAndClear(&mock_object); 98 testing::Mock::VerifyAndClear(&mock_object);
99 99
100 // Expect the task's argument not to have been deleted yet. 100 // Expect the task's argument to have been deleted on the target task runner.
101 EXPECT_FALSE(delete_flag); 101 EXPECT_TRUE(delete_flag);
102 102
103 // Expect the reply to be posted to |reply_runner|. 103 // Expect the reply to be posted to |reply_runner|.
104 EXPECT_FALSE(post_runner->HasPendingTask()); 104 EXPECT_FALSE(post_runner->HasPendingTask());
105 EXPECT_TRUE(reply_runner->HasPendingTask()); 105 EXPECT_TRUE(reply_runner->HasPendingTask());
106 EXPECT_CALL(mock_object, ReplyMock()); 106 EXPECT_CALL(mock_object, ReplyMock());
107 reply_runner->RunUntilIdle(); 107 reply_runner->RunUntilIdle();
108 testing::Mock::VerifyAndClear(&mock_object); 108 testing::Mock::VerifyAndClear(&mock_object);
109 EXPECT_TRUE(delete_flag);
110 109
111 // Expect no pending task in |post_runner| and |reply_runner|. 110 // Expect no pending task in |post_runner| and |reply_runner|.
112 EXPECT_FALSE(post_runner->HasPendingTask()); 111 EXPECT_FALSE(post_runner->HasPendingTask());
113 EXPECT_FALSE(reply_runner->HasPendingTask()); 112 EXPECT_FALSE(reply_runner->HasPendingTask());
114 } 113 }
115 114
116 } // namespace internal 115 } // namespace internal
117 } // namespace base 116 } // namespace base
OLDNEW
« no previous file with comments | « base/threading/post_task_and_reply_impl.cc ('k') | base/threading/sequenced_worker_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698