Fix OnceCallback support of base::ResetAndReturn
ResetAndReturn's OnceCallback was broken, since it tried to copy the move only OnceCallback. This CL fixes that and adds test for it. Review-Url: https://codereview.chromium.org/2709913002 Cr-Commit-Position: refs/heads/master@{#451949}
This commit is contained in:
@ -25,8 +25,8 @@ template <typename Signature,
|
||||
internal::RepeatMode repeat_mode>
|
||||
base::Callback<Signature, copy_mode, repeat_mode> ResetAndReturn(
|
||||
base::Callback<Signature, copy_mode, repeat_mode>* cb) {
|
||||
base::Callback<Signature, copy_mode, repeat_mode> ret(*cb);
|
||||
cb->Reset();
|
||||
base::Callback<Signature, copy_mode, repeat_mode> ret(std::move(*cb));
|
||||
DCHECK(!*cb);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,24 @@ void Increment(int* value) {
|
||||
(*value)++;
|
||||
}
|
||||
|
||||
TEST(CallbackHelpersTest, TestResetAndReturn) {
|
||||
int run_count = 0;
|
||||
|
||||
base::Closure cb = base::Bind(&Increment, &run_count);
|
||||
EXPECT_EQ(0, run_count);
|
||||
base::ResetAndReturn(&cb).Run();
|
||||
EXPECT_EQ(1, run_count);
|
||||
EXPECT_FALSE(cb);
|
||||
|
||||
run_count = 0;
|
||||
|
||||
base::OnceClosure cb2 = base::BindOnce(&Increment, &run_count);
|
||||
EXPECT_EQ(0, run_count);
|
||||
base::ResetAndReturn(&cb2).Run();
|
||||
EXPECT_EQ(1, run_count);
|
||||
EXPECT_FALSE(cb2);
|
||||
}
|
||||
|
||||
TEST(CallbackHelpersTest, TestScopedClosureRunnerExitScope) {
|
||||
int run_count = 0;
|
||||
{
|
||||
|
Reference in New Issue
Block a user