summaryrefslogtreecommitdiffstats
path: root/base/message_loop_proxy_impl_unittest.cc
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-26 18:25:16 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-26 18:25:16 +0000
commit180c85e3e3691042ab617fd0755dcde6e75d5fbd (patch)
treeb9d4fd7a77f7f54dce4463960326ef7b0cd7a270 /base/message_loop_proxy_impl_unittest.cc
parent324ab8e0d77303333f8ad7de3b54d248587687db (diff)
downloadchromium_src-180c85e3e3691042ab617fd0755dcde6e75d5fbd.zip
chromium_src-180c85e3e3691042ab617fd0755dcde6e75d5fbd.tar.gz
chromium_src-180c85e3e3691042ab617fd0755dcde6e75d5fbd.tar.bz2
Support Closure in ALL the loops!
Add an overload for PostTask into MessageLoopProxy, and WorkerPool. BUG=35223 TEST=unittests. Review URL: http://codereview.chromium.org/7316015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94129 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_loop_proxy_impl_unittest.cc')
-rw-r--r--base/message_loop_proxy_impl_unittest.cc48
1 files changed, 44 insertions, 4 deletions
diff --git a/base/message_loop_proxy_impl_unittest.cc b/base/message_loop_proxy_impl_unittest.cc
index 558cd932..d635acb 100644
--- a/base/message_loop_proxy_impl_unittest.cc
+++ b/base/message_loop_proxy_impl_unittest.cc
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/message_loop_proxy_impl.h"
+
+#include "base/bind.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
-#include "base/message_loop_proxy_impl.h"
#include "base/threading/thread.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
@@ -47,6 +49,10 @@ class MessageLoopProxyImplTest : public testing::Test {
test->Quit();
}
+ static void AssertNotRun() {
+ FAIL() << "Callback Should not get executed.";
+ }
+
class DummyTask : public Task {
public:
explicit DummyTask(bool* deleted) : deleted_(deleted) { }
@@ -83,7 +89,7 @@ class MessageLoopProxyImplTest : public testing::Test {
};
-TEST_F(MessageLoopProxyImplTest, PostTask) {
+TEST_F(MessageLoopProxyImplTest, LegacyPostTask) {
EXPECT_TRUE(file_thread_->message_loop_proxy()->PostTask(
FROM_HERE, NewRunnableFunction(&BasicFunction, this)));
MessageLoop::current()->Run();
@@ -101,7 +107,7 @@ TEST_F(MessageLoopProxyImplTest, Delete) {
MessageLoop::current()->Run();
}
-TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadExits) {
+TEST_F(MessageLoopProxyImplTest, LegacyPostTaskAfterThreadExits) {
scoped_ptr<base::Thread> test_thread(
new base::Thread("MessageLoopProxyImplTest_Dummy"));
test_thread->Start();
@@ -116,7 +122,7 @@ TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadExits) {
EXPECT_TRUE(deleted);
}
-TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadIsDeleted) {
+TEST_F(MessageLoopProxyImplTest, LegacyPostTaskAfterThreadIsDeleted) {
scoped_refptr<base::MessageLoopProxy> message_loop_proxy;
{
scoped_ptr<base::Thread> test_thread(
@@ -130,3 +136,37 @@ TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadIsDeleted) {
EXPECT_TRUE(deleted);
}
+TEST_F(MessageLoopProxyImplTest, PostTask) {
+ EXPECT_TRUE(file_thread_->message_loop_proxy()->PostTask(
+ FROM_HERE, base::Bind(&MessageLoopProxyImplTest::BasicFunction,
+ base::Unretained(this))));
+ MessageLoop::current()->Run();
+}
+
+TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadExits) {
+ scoped_ptr<base::Thread> test_thread(
+ new base::Thread("MessageLoopProxyImplTest_Dummy"));
+ test_thread->Start();
+ scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
+ test_thread->message_loop_proxy();
+ test_thread->Stop();
+
+ bool ret = message_loop_proxy->PostTask(
+ FROM_HERE,
+ base::Bind(&MessageLoopProxyImplTest::AssertNotRun));
+ EXPECT_FALSE(ret);
+}
+
+TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadIsDeleted) {
+ scoped_refptr<base::MessageLoopProxy> message_loop_proxy;
+ {
+ scoped_ptr<base::Thread> test_thread(
+ new base::Thread("MessageLoopProxyImplTest_Dummy"));
+ test_thread->Start();
+ message_loop_proxy = test_thread->message_loop_proxy();
+ }
+ bool ret = message_loop_proxy->PostTask(
+ FROM_HERE,
+ base::Bind(&MessageLoopProxyImplTest::AssertNotRun));
+ EXPECT_FALSE(ret);
+}