| Index: base/bind_to_task_runner_unittest.cc
|
| diff --git a/media/base/bind_to_current_loop_unittest.cc b/base/bind_to_task_runner_unittest.cc
|
| similarity index 55%
|
| rename from media/base/bind_to_current_loop_unittest.cc
|
| rename to base/bind_to_task_runner_unittest.cc
|
| index 7fb56d48cdb0444805b42b3a55e21940a45b18e4..d414fcac00ffea32d43d9402f668656c3e07d7e2 100644
|
| --- a/media/base/bind_to_current_loop_unittest.cc
|
| +++ b/base/bind_to_task_runner_unittest.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "media/base/bind_to_current_loop.h"
|
| +#include "base/bind_to_task_runner.h"
|
|
|
| #include <utility>
|
|
|
| @@ -10,7 +10,7 @@
|
| #include "base/synchronization/waitable_event.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| -namespace media {
|
| +namespace base {
|
|
|
| void BoundBoolSet(bool* var, bool val) {
|
| *var = val;
|
| @@ -20,9 +20,8 @@ void BoundBoolSetFromScopedPtr(bool* var, scoped_ptr<bool> val) {
|
| *var = *val;
|
| }
|
|
|
| -void BoundBoolSetFromScopedPtrFreeDeleter(
|
| - bool* var,
|
| - scoped_ptr<bool, base::FreeDeleter> val) {
|
| +void BoundBoolSetFromScopedPtrFreeDeleter(bool* var,
|
| + scoped_ptr<bool, FreeDeleter> val) {
|
| *var = val;
|
| }
|
|
|
| @@ -41,124 +40,121 @@ void BoundIntegersSet(int* a_var, int* b_var, int a_val, int b_val) {
|
|
|
| // Various tests that check that the bound function is only actually executed
|
| // on the message loop, not during the original Run.
|
| -class BindToCurrentLoopTest : public ::testing::Test {
|
| +class BindToTaskRunnerTest : public ::testing::Test {
|
| protected:
|
| - base::MessageLoop loop_;
|
| + MessageLoop loop_;
|
| };
|
|
|
| -TEST_F(BindToCurrentLoopTest, Closure) {
|
| +TEST_F(BindToTaskRunnerTest, Closure) {
|
| // Test the closure is run inside the loop, not outside it.
|
| - base::WaitableEvent waiter(false, false);
|
| - base::Closure cb = BindToCurrentLoop(base::Bind(
|
| - &base::WaitableEvent::Signal, base::Unretained(&waiter)));
|
| + WaitableEvent waiter(false, false);
|
| + Closure cb =
|
| + BindToCurrentThread(Bind(&WaitableEvent::Signal, Unretained(&waiter)));
|
| cb.Run();
|
| EXPECT_FALSE(waiter.IsSignaled());
|
| loop_.RunUntilIdle();
|
| EXPECT_TRUE(waiter.IsSignaled());
|
| }
|
|
|
| -TEST_F(BindToCurrentLoopTest, Bool) {
|
| +TEST_F(BindToTaskRunnerTest, Bool) {
|
| bool bool_var = false;
|
| - base::Callback<void(bool)> cb = BindToCurrentLoop(base::Bind(
|
| - &BoundBoolSet, &bool_var));
|
| + Callback<void(bool)> cb = BindToCurrentThread(Bind(&BoundBoolSet, &bool_var));
|
| cb.Run(true);
|
| EXPECT_FALSE(bool_var);
|
| loop_.RunUntilIdle();
|
| EXPECT_TRUE(bool_var);
|
| }
|
|
|
| -TEST_F(BindToCurrentLoopTest, BoundScopedPtrBool) {
|
| +TEST_F(BindToTaskRunnerTest, BoundScopedPtrBool) {
|
| bool bool_val = false;
|
| scoped_ptr<bool> scoped_ptr_bool(new bool(true));
|
| - base::Closure cb = BindToCurrentLoop(base::Bind(
|
| - &BoundBoolSetFromScopedPtr, &bool_val, base::Passed(&scoped_ptr_bool)));
|
| + Closure cb = BindToCurrentThread(
|
| + Bind(&BoundBoolSetFromScopedPtr, &bool_val, Passed(&scoped_ptr_bool)));
|
| cb.Run();
|
| EXPECT_FALSE(bool_val);
|
| loop_.RunUntilIdle();
|
| EXPECT_TRUE(bool_val);
|
| }
|
|
|
| -TEST_F(BindToCurrentLoopTest, PassedScopedPtrBool) {
|
| +TEST_F(BindToTaskRunnerTest, PassedScopedPtrBool) {
|
| bool bool_val = false;
|
| scoped_ptr<bool> scoped_ptr_bool(new bool(true));
|
| - base::Callback<void(scoped_ptr<bool>)> cb = BindToCurrentLoop(base::Bind(
|
| - &BoundBoolSetFromScopedPtr, &bool_val));
|
| + Callback<void(scoped_ptr<bool>)> cb =
|
| + BindToCurrentThread(Bind(&BoundBoolSetFromScopedPtr, &bool_val));
|
| cb.Run(std::move(scoped_ptr_bool));
|
| EXPECT_FALSE(bool_val);
|
| loop_.RunUntilIdle();
|
| EXPECT_TRUE(bool_val);
|
| }
|
|
|
| -TEST_F(BindToCurrentLoopTest, BoundScopedArrayBool) {
|
| +TEST_F(BindToTaskRunnerTest, BoundScopedArrayBool) {
|
| bool bool_val = false;
|
| scoped_ptr<bool[]> scoped_array_bool(new bool[1]);
|
| scoped_array_bool[0] = true;
|
| - base::Closure cb = BindToCurrentLoop(base::Bind(
|
| - &BoundBoolSetFromScopedArray, &bool_val,
|
| - base::Passed(&scoped_array_bool)));
|
| + Closure cb = BindToCurrentThread(Bind(&BoundBoolSetFromScopedArray, &bool_val,
|
| + Passed(&scoped_array_bool)));
|
| cb.Run();
|
| EXPECT_FALSE(bool_val);
|
| loop_.RunUntilIdle();
|
| EXPECT_TRUE(bool_val);
|
| }
|
|
|
| -TEST_F(BindToCurrentLoopTest, PassedScopedArrayBool) {
|
| +TEST_F(BindToTaskRunnerTest, PassedScopedArrayBool) {
|
| bool bool_val = false;
|
| scoped_ptr<bool[]> scoped_array_bool(new bool[1]);
|
| scoped_array_bool[0] = true;
|
| - base::Callback<void(scoped_ptr<bool[]>)> cb = BindToCurrentLoop(base::Bind(
|
| - &BoundBoolSetFromScopedArray, &bool_val));
|
| + Callback<void(scoped_ptr<bool[]>)> cb =
|
| + BindToCurrentThread(Bind(&BoundBoolSetFromScopedArray, &bool_val));
|
| cb.Run(std::move(scoped_array_bool));
|
| EXPECT_FALSE(bool_val);
|
| loop_.RunUntilIdle();
|
| EXPECT_TRUE(bool_val);
|
| }
|
|
|
| -TEST_F(BindToCurrentLoopTest, BoundScopedPtrFreeDeleterBool) {
|
| +TEST_F(BindToTaskRunnerTest, BoundScopedPtrFreeDeleterBool) {
|
| bool bool_val = false;
|
| - scoped_ptr<bool, base::FreeDeleter> scoped_ptr_free_deleter_bool(
|
| + scoped_ptr<bool, FreeDeleter> scoped_ptr_free_deleter_bool(
|
| static_cast<bool*>(malloc(sizeof(bool))));
|
| *scoped_ptr_free_deleter_bool = true;
|
| - base::Closure cb = BindToCurrentLoop(base::Bind(
|
| - &BoundBoolSetFromScopedPtrFreeDeleter, &bool_val,
|
| - base::Passed(&scoped_ptr_free_deleter_bool)));
|
| + Closure cb =
|
| + BindToCurrentThread(Bind(&BoundBoolSetFromScopedPtrFreeDeleter, &bool_val,
|
| + Passed(&scoped_ptr_free_deleter_bool)));
|
| cb.Run();
|
| EXPECT_FALSE(bool_val);
|
| loop_.RunUntilIdle();
|
| EXPECT_TRUE(bool_val);
|
| }
|
|
|
| -TEST_F(BindToCurrentLoopTest, PassedScopedPtrFreeDeleterBool) {
|
| +TEST_F(BindToTaskRunnerTest, PassedScopedPtrFreeDeleterBool) {
|
| bool bool_val = false;
|
| - scoped_ptr<bool, base::FreeDeleter> scoped_ptr_free_deleter_bool(
|
| + scoped_ptr<bool, FreeDeleter> scoped_ptr_free_deleter_bool(
|
| static_cast<bool*>(malloc(sizeof(bool))));
|
| *scoped_ptr_free_deleter_bool = true;
|
| - base::Callback<void(scoped_ptr<bool, base::FreeDeleter>)> cb =
|
| - BindToCurrentLoop(base::Bind(&BoundBoolSetFromScopedPtrFreeDeleter,
|
| - &bool_val));
|
| + Callback<void(scoped_ptr<bool, FreeDeleter>)> cb = BindToCurrentThread(
|
| + Bind(&BoundBoolSetFromScopedPtrFreeDeleter, &bool_val));
|
| cb.Run(std::move(scoped_ptr_free_deleter_bool));
|
| EXPECT_FALSE(bool_val);
|
| loop_.RunUntilIdle();
|
| EXPECT_TRUE(bool_val);
|
| }
|
|
|
| -TEST_F(BindToCurrentLoopTest, BoolConstRef) {
|
| +TEST_F(BindToTaskRunnerTest, BoolConstRef) {
|
| bool bool_var = false;
|
| bool true_var = true;
|
| const bool& true_ref = true_var;
|
| - base::Closure cb = BindToCurrentLoop(base::Bind(
|
| - &BoundBoolSetFromConstRef, &bool_var, true_ref));
|
| + Closure cb =
|
| + BindToCurrentThread(Bind(&BoundBoolSetFromConstRef, &bool_var, true_ref));
|
| cb.Run();
|
| EXPECT_FALSE(bool_var);
|
| loop_.RunUntilIdle();
|
| EXPECT_TRUE(bool_var);
|
| }
|
|
|
| -TEST_F(BindToCurrentLoopTest, Integers) {
|
| +TEST_F(BindToTaskRunnerTest, Integers) {
|
| int a = 0;
|
| int b = 0;
|
| - base::Callback<void(int, int)> cb = BindToCurrentLoop(base::Bind(
|
| - &BoundIntegersSet, &a, &b));
|
| + Callback<void(int, int)> cb =
|
| + BindToCurrentThread(Bind(&BoundIntegersSet, &a, &b));
|
| cb.Run(1, -1);
|
| EXPECT_EQ(a, 0);
|
| EXPECT_EQ(b, 0);
|
| @@ -167,4 +163,4 @@ TEST_F(BindToCurrentLoopTest, Integers) {
|
| EXPECT_EQ(b, -1);
|
| }
|
|
|
| -} // namespace media
|
| +} // namespace base
|
|
|