Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: base/message_loop_unittest.cc

Issue 6507017: MessagePump implementations should call DoWork and DoDelayedWork at equal priority (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/message_pump.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/eintr_wrapper.h" 7 #include "base/eintr_wrapper.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/ref_counted.h" 10 #include "base/ref_counted.h"
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 new RecursiveTask(depth_ - 1, order(), cookie(), is_reentrant_)); 761 new RecursiveTask(depth_ - 1, order(), cookie(), is_reentrant_));
762 } 762 }
763 RunEnd(); 763 RunEnd();
764 } 764 }
765 765
766 private: 766 private:
767 int depth_; 767 int depth_;
768 bool is_reentrant_; 768 bool is_reentrant_;
769 }; 769 };
770 770
771 class RecursiveSlowTask : public RecursiveTask {
772 public:
773 RecursiveSlowTask(int depth, TaskList* order, int cookie, bool is_reentrant)
774 : RecursiveTask(depth, order, cookie, is_reentrant) {
775 }
776
777 virtual void Run() {
778 RecursiveTask::Run();
779 PlatformThread::Sleep(10); // milliseconds
780 }
781 };
782
771 class QuitTask : public OrderedTasks { 783 class QuitTask : public OrderedTasks {
772 public: 784 public:
773 QuitTask(TaskList* order, int cookie) 785 QuitTask(TaskList* order, int cookie)
774 : OrderedTasks(order, QUITMESSAGELOOP, cookie) { 786 : OrderedTasks(order, QUITMESSAGELOOP, cookie) {
775 } 787 }
776 788
777 virtual void Run() { 789 virtual void Run() {
778 RunStart(); 790 RunStart();
779 MessageLoop::current()->Quit(); 791 MessageLoop::current()->Quit();
780 RunEnd(); 792 RunEnd();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 EXPECT_EQ(order[ 6], TaskItem(RECURSIVE, 1, true)); 898 EXPECT_EQ(order[ 6], TaskItem(RECURSIVE, 1, true));
887 EXPECT_EQ(order[ 7], TaskItem(RECURSIVE, 1, false)); 899 EXPECT_EQ(order[ 7], TaskItem(RECURSIVE, 1, false));
888 EXPECT_EQ(order[ 8], TaskItem(RECURSIVE, 2, true)); 900 EXPECT_EQ(order[ 8], TaskItem(RECURSIVE, 2, true));
889 EXPECT_EQ(order[ 9], TaskItem(RECURSIVE, 2, false)); 901 EXPECT_EQ(order[ 9], TaskItem(RECURSIVE, 2, false));
890 EXPECT_EQ(order[10], TaskItem(RECURSIVE, 1, true)); 902 EXPECT_EQ(order[10], TaskItem(RECURSIVE, 1, true));
891 EXPECT_EQ(order[11], TaskItem(RECURSIVE, 1, false)); 903 EXPECT_EQ(order[11], TaskItem(RECURSIVE, 1, false));
892 EXPECT_EQ(order[12], TaskItem(RECURSIVE, 2, true)); 904 EXPECT_EQ(order[12], TaskItem(RECURSIVE, 2, true));
893 EXPECT_EQ(order[13], TaskItem(RECURSIVE, 2, false)); 905 EXPECT_EQ(order[13], TaskItem(RECURSIVE, 2, false));
894 } 906 }
895 907
908 void RunTest_RecursiveDenial3(MessageLoop::Type message_loop_type) {
909 MessageLoop loop(message_loop_type);
910
911 EXPECT_TRUE(MessageLoop::current()->NestableTasksAllowed());
912 TaskList order;
913 MessageLoop::current()->PostTask(FROM_HERE,
914 new RecursiveSlowTask(2, &order, 1, false));
915 MessageLoop::current()->PostTask(FROM_HERE,
916 new RecursiveSlowTask(2, &order, 2, false));
917 MessageLoop::current()->PostDelayedTask(FROM_HERE,
918 new OrderedTasks(&order, 3), 5);
919 MessageLoop::current()->PostDelayedTask(FROM_HERE,
920 new QuitTask(&order, 4), 5);
921
922 MessageLoop::current()->Run();
923
924 // FIFO order.
925 ASSERT_EQ(16U, order.size());
926 EXPECT_EQ(order[ 0], TaskItem(RECURSIVE, 1, true));
927 EXPECT_EQ(order[ 1], TaskItem(RECURSIVE, 1, false));
928 EXPECT_EQ(order[ 2], TaskItem(RECURSIVE, 2, true));
929 EXPECT_EQ(order[ 3], TaskItem(RECURSIVE, 2, false));
930 EXPECT_EQ(order[ 4], TaskItem(RECURSIVE, 1, true));
931 EXPECT_EQ(order[ 5], TaskItem(RECURSIVE, 1, false));
932 EXPECT_EQ(order[ 6], TaskItem(ORDERERD, 3, true));
933 EXPECT_EQ(order[ 7], TaskItem(ORDERERD, 3, false));
934 EXPECT_EQ(order[ 8], TaskItem(RECURSIVE, 2, true));
935 EXPECT_EQ(order[ 9], TaskItem(RECURSIVE, 2, false));
936 EXPECT_EQ(order[10], TaskItem(QUITMESSAGELOOP, 4, true));
937 EXPECT_EQ(order[11], TaskItem(QUITMESSAGELOOP, 4, false));
938 EXPECT_EQ(order[12], TaskItem(RECURSIVE, 1, true));
939 EXPECT_EQ(order[13], TaskItem(RECURSIVE, 1, false));
940 EXPECT_EQ(order[14], TaskItem(RECURSIVE, 2, true));
941 EXPECT_EQ(order[15], TaskItem(RECURSIVE, 2, false));
942 }
943
896 void RunTest_RecursiveSupport1(MessageLoop::Type message_loop_type) { 944 void RunTest_RecursiveSupport1(MessageLoop::Type message_loop_type) {
897 MessageLoop loop(message_loop_type); 945 MessageLoop loop(message_loop_type);
898 946
899 TaskList order; 947 TaskList order;
900 MessageLoop::current()->PostTask(FROM_HERE, 948 MessageLoop::current()->PostTask(FROM_HERE,
901 new RecursiveTask(2, &order, 1, true)); 949 new RecursiveTask(2, &order, 1, true));
902 MessageLoop::current()->PostTask(FROM_HERE, 950 MessageLoop::current()->PostTask(FROM_HERE,
903 new RecursiveTask(2, &order, 2, true)); 951 new RecursiveTask(2, &order, 2, true));
904 MessageLoop::current()->PostTask(FROM_HERE, 952 MessageLoop::current()->PostTask(FROM_HERE,
905 new QuitTask(&order, 3)); 953 new QuitTask(&order, 3));
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 RunTest_Nesting(MessageLoop::TYPE_UI); 1467 RunTest_Nesting(MessageLoop::TYPE_UI);
1420 RunTest_Nesting(MessageLoop::TYPE_IO); 1468 RunTest_Nesting(MessageLoop::TYPE_IO);
1421 } 1469 }
1422 1470
1423 TEST(MessageLoopTest, RecursiveDenial1) { 1471 TEST(MessageLoopTest, RecursiveDenial1) {
1424 RunTest_RecursiveDenial1(MessageLoop::TYPE_DEFAULT); 1472 RunTest_RecursiveDenial1(MessageLoop::TYPE_DEFAULT);
1425 RunTest_RecursiveDenial1(MessageLoop::TYPE_UI); 1473 RunTest_RecursiveDenial1(MessageLoop::TYPE_UI);
1426 RunTest_RecursiveDenial1(MessageLoop::TYPE_IO); 1474 RunTest_RecursiveDenial1(MessageLoop::TYPE_IO);
1427 } 1475 }
1428 1476
1477 TEST(MessageLoopTest, RecursiveDenial3) {
1478 RunTest_RecursiveDenial3(MessageLoop::TYPE_DEFAULT);
1479 RunTest_RecursiveDenial3(MessageLoop::TYPE_UI);
1480 RunTest_RecursiveDenial3(MessageLoop::TYPE_IO);
1481 }
1482
1429 TEST(MessageLoopTest, RecursiveSupport1) { 1483 TEST(MessageLoopTest, RecursiveSupport1) {
1430 RunTest_RecursiveSupport1(MessageLoop::TYPE_DEFAULT); 1484 RunTest_RecursiveSupport1(MessageLoop::TYPE_DEFAULT);
1431 RunTest_RecursiveSupport1(MessageLoop::TYPE_UI); 1485 RunTest_RecursiveSupport1(MessageLoop::TYPE_UI);
1432 RunTest_RecursiveSupport1(MessageLoop::TYPE_IO); 1486 RunTest_RecursiveSupport1(MessageLoop::TYPE_IO);
1433 } 1487 }
1434 1488
1435 #if defined(OS_WIN) 1489 #if defined(OS_WIN)
1436 // This test occasionally hangs http://crbug.com/44567 1490 // This test occasionally hangs http://crbug.com/44567
1437 TEST(MessageLoopTest, DISABLED_RecursiveDenial2) { 1491 TEST(MessageLoopTest, DISABLED_RecursiveDenial2) {
1438 RunTest_RecursiveDenial2(MessageLoop::TYPE_DEFAULT); 1492 RunTest_RecursiveDenial2(MessageLoop::TYPE_DEFAULT);
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1707 loop->PostDelayedTask( 1761 loop->PostDelayedTask(
1708 FROM_HERE, 1762 FROM_HERE,
1709 new RunAtDestructionTask(&task_destroyed, &destruction_observer_called), 1763 new RunAtDestructionTask(&task_destroyed, &destruction_observer_called),
1710 kDelayMS); 1764 kDelayMS);
1711 delete loop; 1765 delete loop;
1712 EXPECT_TRUE(observer.task_destroyed_before_message_loop()); 1766 EXPECT_TRUE(observer.task_destroyed_before_message_loop());
1713 // The task should have been destroyed when we deleted the loop. 1767 // The task should have been destroyed when we deleted the loop.
1714 EXPECT_TRUE(task_destroyed); 1768 EXPECT_TRUE(task_destroyed);
1715 EXPECT_TRUE(destruction_observer_called); 1769 EXPECT_TRUE(destruction_observer_called);
1716 } 1770 }
OLDNEW
« no previous file with comments | « no previous file | base/message_pump.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698