OLD | NEW |
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 <utility> | 7 #include <utility> |
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 scoped_refptr<TestSimpleTaskRunner> reply_runner(new TestSimpleTaskRunner); | 71 scoped_refptr<TestSimpleTaskRunner> reply_runner(new TestSimpleTaskRunner); |
72 ThreadTaskRunnerHandle task_runner_handle(reply_runner); | 72 ThreadTaskRunnerHandle task_runner_handle(reply_runner); |
73 | 73 |
74 testing::StrictMock<MockObject> mock_object; | 74 testing::StrictMock<MockObject> mock_object; |
75 bool delete_flag = false; | 75 bool delete_flag = false; |
76 | 76 |
77 EXPECT_TRUE( | 77 EXPECT_TRUE( |
78 PostTaskAndReplyTaskRunner(post_runner.get()) | 78 PostTaskAndReplyTaskRunner(post_runner.get()) |
79 .PostTaskAndReply( | 79 .PostTaskAndReply( |
80 FROM_HERE, | 80 FROM_HERE, |
81 Bind(&MockObject::Task, Unretained(&mock_object), | 81 BindOnce(&MockObject::Task, Unretained(&mock_object), |
82 make_scoped_refptr(new ObjectToDelete(&delete_flag))), | 82 make_scoped_refptr(new ObjectToDelete(&delete_flag))), |
83 Bind(&MockObject::Reply, Unretained(&mock_object)))); | 83 BindOnce(&MockObject::Reply, Unretained(&mock_object)))); |
84 | 84 |
85 // Expect the task to be posted to |post_runner|. | 85 // Expect the task to be posted to |post_runner|. |
86 EXPECT_TRUE(post_runner->HasPendingTask()); | 86 EXPECT_TRUE(post_runner->HasPendingTask()); |
87 EXPECT_FALSE(reply_runner->HasPendingTask()); | 87 EXPECT_FALSE(reply_runner->HasPendingTask()); |
88 EXPECT_FALSE(delete_flag); | 88 EXPECT_FALSE(delete_flag); |
89 | 89 |
90 EXPECT_CALL(mock_object, Task(_)); | 90 EXPECT_CALL(mock_object, Task(_)); |
91 post_runner->RunUntilIdle(); | 91 post_runner->RunUntilIdle(); |
92 testing::Mock::VerifyAndClear(&mock_object); | 92 testing::Mock::VerifyAndClear(&mock_object); |
93 | 93 |
94 // |task| should have been deleted right after being run. | 94 // |task| should have been deleted right after being run. |
95 EXPECT_TRUE(delete_flag); | 95 EXPECT_TRUE(delete_flag); |
96 | 96 |
97 // Expect the reply to be posted to |reply_runner|. | 97 // Expect the reply to be posted to |reply_runner|. |
98 EXPECT_FALSE(post_runner->HasPendingTask()); | 98 EXPECT_FALSE(post_runner->HasPendingTask()); |
99 EXPECT_TRUE(reply_runner->HasPendingTask()); | 99 EXPECT_TRUE(reply_runner->HasPendingTask()); |
100 | 100 |
101 EXPECT_CALL(mock_object, Reply()); | 101 EXPECT_CALL(mock_object, Reply()); |
102 reply_runner->RunUntilIdle(); | 102 reply_runner->RunUntilIdle(); |
103 testing::Mock::VerifyAndClear(&mock_object); | 103 testing::Mock::VerifyAndClear(&mock_object); |
104 EXPECT_TRUE(delete_flag); | 104 EXPECT_TRUE(delete_flag); |
105 | 105 |
106 // Expect no pending task in |post_runner| and |reply_runner|. | 106 // Expect no pending task in |post_runner| and |reply_runner|. |
107 EXPECT_FALSE(post_runner->HasPendingTask()); | 107 EXPECT_FALSE(post_runner->HasPendingTask()); |
108 EXPECT_FALSE(reply_runner->HasPendingTask()); | 108 EXPECT_FALSE(reply_runner->HasPendingTask()); |
109 } | 109 } |
110 | 110 |
111 } // namespace internal | 111 } // namespace internal |
112 } // namespace base | 112 } // namespace base |
OLD | NEW |