diff options
author | rsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-03 22:34:17 +0000 |
---|---|---|
committer | rsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-03 22:34:17 +0000 |
commit | d53e6a6c73062427e7408cf4cb156938ac509311 (patch) | |
tree | e98959728b1d1ab9717753b3b6189f7bd375c034 /base/task_runner_util_unittest.cc | |
parent | 3f24ae2243c95d0907a4447b799b37e8569650a0 (diff) | |
download | chromium_src-d53e6a6c73062427e7408cf4cb156938ac509311.zip chromium_src-d53e6a6c73062427e7408cf4cb156938ac509311.tar.gz chromium_src-d53e6a6c73062427e7408cf4cb156938ac509311.tar.bz2 |
When using PostTaskAndReplyWithResults, if the ResultType is a passed type (eg: scoped_ptr and friends), .Pass() the result to the reply.
Because the temporary storage of the result is an implementation detail of PostTaskAndReplyWithResults, its safe to always assume that passed types should be passed.
BUG=126008
TEST=TaskRunnerHelpersTest.PostTaskAndReplyWithResultPassed
Review URL: http://codereview.chromium.org/10344012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135228 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/task_runner_util_unittest.cc')
-rw-r--r-- | base/task_runner_util_unittest.cc | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/base/task_runner_util_unittest.cc b/base/task_runner_util_unittest.cc index 4c58826..daed770 100644 --- a/base/task_runner_util_unittest.cc +++ b/base/task_runner_util_unittest.cc @@ -20,9 +20,28 @@ void StoreValue(int* destination, int value) { *destination = value; } +int g_foo_destruct_count = 0; + +struct Foo { + ~Foo() { + ++g_foo_destruct_count; + } +}; + +scoped_ptr<Foo> CreateFoo() { + return scoped_ptr<Foo>(new Foo); +} + +void ExpectFoo(scoped_ptr<Foo> foo) { + EXPECT_TRUE(foo.get()); + scoped_ptr<Foo> local_foo(foo.Pass()); + EXPECT_TRUE(local_foo.get()); + EXPECT_FALSE(foo.get()); +} + } // namespace -TEST(TaskRunnerHelpersTest, PostAndReplyWithStatus) { +TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResult) { MessageLoop message_loop; int result = 0; @@ -37,4 +56,20 @@ TEST(TaskRunnerHelpersTest, PostAndReplyWithStatus) { EXPECT_EQ(42, result); } +TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassed) { + g_foo_destruct_count = 0; + + MessageLoop message_loop; + + PostTaskAndReplyWithResult( + message_loop.message_loop_proxy(), + FROM_HERE, + Bind(&CreateFoo), + Bind(&ExpectFoo)); + + message_loop.RunAllPending(); + + EXPECT_EQ(1, g_foo_destruct_count); +} + } // namespace base |