summaryrefslogtreecommitdiffstats
path: root/base/message_loop_unittest.cc
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-10 00:37:07 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-10 00:37:07 +0000
commit001747c6c07c3755ca7ac136e6b7cecfe2afec1b (patch)
treea64579f732d3e22971daba019d09e040afd45ade /base/message_loop_unittest.cc
parentcc6cd3484260c20f59a6abd8f52d7b1f18b2e973 (diff)
downloadchromium_src-001747c6c07c3755ca7ac136e6b7cecfe2afec1b.zip
chromium_src-001747c6c07c3755ca7ac136e6b7cecfe2afec1b.tar.gz
chromium_src-001747c6c07c3755ca7ac136e6b7cecfe2afec1b.tar.bz2
Put back r1891 with some task deletion disabled to maintain backwards compat and thereby avoid unexpected crashes.
r=jar Review URL: http://codereview.chromium.org/1664 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1959 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_loop_unittest.cc')
-rw-r--r--base/message_loop_unittest.cc58
1 files changed, 58 insertions, 0 deletions
diff --git a/base/message_loop_unittest.cc b/base/message_loop_unittest.cc
index b36090a6d..e79c576 100644
--- a/base/message_loop_unittest.cc
+++ b/base/message_loop_unittest.cc
@@ -290,6 +290,52 @@ void RunTest_PostDelayedTask_InPostOrder_3(MessageLoop::Type message_loop_type)
EXPECT_TRUE(run_time2 > run_time1);
}
+class RecordDeletionTask : public Task {
+ public:
+ RecordDeletionTask(Task* post_on_delete, bool* was_deleted)
+ : post_on_delete_(post_on_delete), was_deleted_(was_deleted) {
+ }
+ ~RecordDeletionTask() {
+ *was_deleted_ = true;
+ if (post_on_delete_)
+ MessageLoop::current()->PostTask(FROM_HERE, post_on_delete_);
+ }
+ virtual void Run() {}
+ private:
+ Task* post_on_delete_;
+ bool* was_deleted_;
+};
+
+void RunTest_EnsureTaskDeletion(MessageLoop::Type message_loop_type) {
+ bool a_was_deleted = false;
+ bool b_was_deleted = false;
+ {
+ MessageLoop loop(message_loop_type);
+ loop.PostTask(
+ FROM_HERE, new RecordDeletionTask(NULL, &a_was_deleted));
+ loop.PostDelayedTask(
+ FROM_HERE, new RecordDeletionTask(NULL, &b_was_deleted), 1000);
+ }
+ EXPECT_TRUE(a_was_deleted);
+ EXPECT_TRUE(b_was_deleted);
+}
+
+void RunTest_EnsureTaskDeletion_Chain(MessageLoop::Type message_loop_type) {
+ bool a_was_deleted = false;
+ bool b_was_deleted = false;
+ bool c_was_deleted = false;
+ {
+ MessageLoop loop(message_loop_type);
+ RecordDeletionTask* a = new RecordDeletionTask(NULL, &a_was_deleted);
+ RecordDeletionTask* b = new RecordDeletionTask(a, &b_was_deleted);
+ RecordDeletionTask* c = new RecordDeletionTask(b, &c_was_deleted);
+ loop.PostTask(FROM_HERE, c);
+ }
+ EXPECT_TRUE(a_was_deleted);
+ EXPECT_TRUE(b_was_deleted);
+ EXPECT_TRUE(c_was_deleted);
+}
+
class NestingTest : public Task {
public:
explicit NestingTest(int* depth) : depth_(depth) {
@@ -1049,6 +1095,18 @@ TEST(MessageLoopTest, PostDelayedTask_InPostOrder_3) {
RunTest_PostDelayedTask_InPostOrder_3(MessageLoop::TYPE_IO);
}
+TEST(MessageLoopTest, EnsureTaskDeletion) {
+ RunTest_EnsureTaskDeletion(MessageLoop::TYPE_DEFAULT);
+ RunTest_EnsureTaskDeletion(MessageLoop::TYPE_UI);
+ RunTest_EnsureTaskDeletion(MessageLoop::TYPE_IO);
+}
+
+TEST(MessageLoopTest, EnsureTaskDeletion_Chain) {
+ RunTest_EnsureTaskDeletion_Chain(MessageLoop::TYPE_DEFAULT);
+ RunTest_EnsureTaskDeletion_Chain(MessageLoop::TYPE_UI);
+ RunTest_EnsureTaskDeletion_Chain(MessageLoop::TYPE_IO);
+}
+
#if defined(OS_WIN)
TEST(MessageLoopTest, Crasher) {
RunTest_Crasher(MessageLoop::TYPE_DEFAULT);