summaryrefslogtreecommitdiffstats
path: root/base/message_loop_unittest.cc
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 19:25:04 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-17 19:25:04 +0000
commit4554c236675f1d938a358738f300021487b8c34e (patch)
tree6139f3ba54d6a0fe2a1ed7d69a93c6cb3e9cd39b /base/message_loop_unittest.cc
parent637d3443eccf1633e28ec473e8e2f36611d7b148 (diff)
downloadchromium_src-4554c236675f1d938a358738f300021487b8c34e.zip
chromium_src-4554c236675f1d938a358738f300021487b8c34e.tar.gz
chromium_src-4554c236675f1d938a358738f300021487b8c34e.tar.bz2
MessagePump implementations should call DoWork and DoDelayedWork at equal
priority. BUG=72007 TEST=base_unittests --gtest_filter=MessageLoopTest.RecursiveDenial3 Review URL: http://codereview.chromium.org/6507017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75294 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_loop_unittest.cc')
-rw-r--r--base/message_loop_unittest.cc54
1 files changed, 54 insertions, 0 deletions
diff --git a/base/message_loop_unittest.cc b/base/message_loop_unittest.cc
index 9576a58..2869bb8 100644
--- a/base/message_loop_unittest.cc
+++ b/base/message_loop_unittest.cc
@@ -768,6 +768,18 @@ class RecursiveTask : public OrderedTasks {
bool is_reentrant_;
};
+class RecursiveSlowTask : public RecursiveTask {
+ public:
+ RecursiveSlowTask(int depth, TaskList* order, int cookie, bool is_reentrant)
+ : RecursiveTask(depth, order, cookie, is_reentrant) {
+ }
+
+ virtual void Run() {
+ RecursiveTask::Run();
+ PlatformThread::Sleep(10); // milliseconds
+ }
+};
+
class QuitTask : public OrderedTasks {
public:
QuitTask(TaskList* order, int cookie)
@@ -893,6 +905,42 @@ void RunTest_RecursiveDenial1(MessageLoop::Type message_loop_type) {
EXPECT_EQ(order[13], TaskItem(RECURSIVE, 2, false));
}
+void RunTest_RecursiveDenial3(MessageLoop::Type message_loop_type) {
+ MessageLoop loop(message_loop_type);
+
+ EXPECT_TRUE(MessageLoop::current()->NestableTasksAllowed());
+ TaskList order;
+ MessageLoop::current()->PostTask(FROM_HERE,
+ new RecursiveSlowTask(2, &order, 1, false));
+ MessageLoop::current()->PostTask(FROM_HERE,
+ new RecursiveSlowTask(2, &order, 2, false));
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ new OrderedTasks(&order, 3), 5);
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ new QuitTask(&order, 4), 5);
+
+ MessageLoop::current()->Run();
+
+ // FIFO order.
+ ASSERT_EQ(16U, order.size());
+ EXPECT_EQ(order[ 0], TaskItem(RECURSIVE, 1, true));
+ EXPECT_EQ(order[ 1], TaskItem(RECURSIVE, 1, false));
+ EXPECT_EQ(order[ 2], TaskItem(RECURSIVE, 2, true));
+ EXPECT_EQ(order[ 3], TaskItem(RECURSIVE, 2, false));
+ EXPECT_EQ(order[ 4], TaskItem(RECURSIVE, 1, true));
+ EXPECT_EQ(order[ 5], TaskItem(RECURSIVE, 1, false));
+ EXPECT_EQ(order[ 6], TaskItem(ORDERERD, 3, true));
+ EXPECT_EQ(order[ 7], TaskItem(ORDERERD, 3, false));
+ EXPECT_EQ(order[ 8], TaskItem(RECURSIVE, 2, true));
+ EXPECT_EQ(order[ 9], TaskItem(RECURSIVE, 2, false));
+ EXPECT_EQ(order[10], TaskItem(QUITMESSAGELOOP, 4, true));
+ EXPECT_EQ(order[11], TaskItem(QUITMESSAGELOOP, 4, false));
+ EXPECT_EQ(order[12], TaskItem(RECURSIVE, 1, true));
+ EXPECT_EQ(order[13], TaskItem(RECURSIVE, 1, false));
+ EXPECT_EQ(order[14], TaskItem(RECURSIVE, 2, true));
+ EXPECT_EQ(order[15], TaskItem(RECURSIVE, 2, false));
+}
+
void RunTest_RecursiveSupport1(MessageLoop::Type message_loop_type) {
MessageLoop loop(message_loop_type);
@@ -1426,6 +1474,12 @@ TEST(MessageLoopTest, RecursiveDenial1) {
RunTest_RecursiveDenial1(MessageLoop::TYPE_IO);
}
+TEST(MessageLoopTest, RecursiveDenial3) {
+ RunTest_RecursiveDenial3(MessageLoop::TYPE_DEFAULT);
+ RunTest_RecursiveDenial3(MessageLoop::TYPE_UI);
+ RunTest_RecursiveDenial3(MessageLoop::TYPE_IO);
+}
+
TEST(MessageLoopTest, RecursiveSupport1) {
RunTest_RecursiveSupport1(MessageLoop::TYPE_DEFAULT);
RunTest_RecursiveSupport1(MessageLoop::TYPE_UI);