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

Side by Side Diff: base/message_loop/message_loop_test.cc

Issue 1926813005: Remove MessageLoop::PostNonNestableDelayedTask(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ios Created 4 years, 7 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
« no previous file with comments | « base/message_loop/message_loop_test.h ('k') | ios/web/web_thread_impl.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/message_loop/message_loop_test.h" 5 #include "base/message_loop/message_loop_test.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 order->RecordEnd(PUMPS, cookie); 630 order->RecordEnd(PUMPS, cookie);
631 } 631 }
632 632
633 void SleepFunc(TaskList* order, int cookie, TimeDelta delay) { 633 void SleepFunc(TaskList* order, int cookie, TimeDelta delay) {
634 order->RecordStart(SLEEP, cookie); 634 order->RecordStart(SLEEP, cookie);
635 PlatformThread::Sleep(delay); 635 PlatformThread::Sleep(delay);
636 order->RecordEnd(SLEEP, cookie); 636 order->RecordEnd(SLEEP, cookie);
637 } 637 }
638 638
639 // Tests that non nestable tasks don't run when there's code in the call stack. 639 // Tests that non nestable tasks don't run when there's code in the call stack.
640 void RunTest_NonNestableInNestedLoop(MessagePumpFactory factory, 640 void RunTest_NonNestableInNestedLoop(MessagePumpFactory factory) {
641 bool use_delayed) {
642 std::unique_ptr<MessagePump> pump(factory()); 641 std::unique_ptr<MessagePump> pump(factory());
643 MessageLoop loop(std::move(pump)); 642 MessageLoop loop(std::move(pump));
644 643
645 TaskList order; 644 TaskList order;
646 645
647 MessageLoop::current()->PostTask( 646 MessageLoop::current()->PostTask(
648 FROM_HERE, 647 FROM_HERE,
649 Bind(&FuncThatPumps, &order, 1)); 648 Bind(&FuncThatPumps, &order, 1));
650 if (use_delayed) { 649 MessageLoop::current()->PostNonNestableTask(
651 MessageLoop::current()->PostNonNestableDelayedTask( 650 FROM_HERE,
652 FROM_HERE, 651 Bind(&OrderedFunc, &order, 2));
653 Bind(&OrderedFunc, &order, 2),
654 TimeDelta::FromMilliseconds(1));
655 } else {
656 MessageLoop::current()->PostNonNestableTask(
657 FROM_HERE,
658 Bind(&OrderedFunc, &order, 2));
659 }
660 MessageLoop::current()->PostTask(FROM_HERE, 652 MessageLoop::current()->PostTask(FROM_HERE,
661 Bind(&OrderedFunc, &order, 3)); 653 Bind(&OrderedFunc, &order, 3));
662 MessageLoop::current()->PostTask( 654 MessageLoop::current()->PostTask(
663 FROM_HERE, 655 FROM_HERE,
664 Bind(&SleepFunc, &order, 4, TimeDelta::FromMilliseconds(50))); 656 Bind(&SleepFunc, &order, 4, TimeDelta::FromMilliseconds(50)));
665 MessageLoop::current()->PostTask(FROM_HERE, 657 MessageLoop::current()->PostTask(FROM_HERE,
666 Bind(&OrderedFunc, &order, 5)); 658 Bind(&OrderedFunc, &order, 5));
667 if (use_delayed) { 659 MessageLoop::current()->PostNonNestableTask(
668 MessageLoop::current()->PostNonNestableDelayedTask( 660 FROM_HERE,
669 FROM_HERE, 661 Bind(&QuitFunc, &order, 6));
670 Bind(&QuitFunc, &order, 6),
671 TimeDelta::FromMilliseconds(2));
672 } else {
673 MessageLoop::current()->PostNonNestableTask(
674 FROM_HERE,
675 Bind(&QuitFunc, &order, 6));
676 }
677 662
678 MessageLoop::current()->Run(); 663 MessageLoop::current()->Run();
679 664
680 // FIFO order. 665 // FIFO order.
681 ASSERT_EQ(12U, order.Size()); 666 ASSERT_EQ(12U, order.Size());
682 EXPECT_EQ(order.Get(0), TaskItem(PUMPS, 1, true)); 667 EXPECT_EQ(order.Get(0), TaskItem(PUMPS, 1, true));
683 EXPECT_EQ(order.Get(1), TaskItem(ORDERED, 3, true)); 668 EXPECT_EQ(order.Get(1), TaskItem(ORDERED, 3, true));
684 EXPECT_EQ(order.Get(2), TaskItem(ORDERED, 3, false)); 669 EXPECT_EQ(order.Get(2), TaskItem(ORDERED, 3, false));
685 EXPECT_EQ(order.Get(3), TaskItem(SLEEP, 4, true)); 670 EXPECT_EQ(order.Get(3), TaskItem(SLEEP, 4, true));
686 EXPECT_EQ(order.Get(4), TaskItem(SLEEP, 4, false)); 671 EXPECT_EQ(order.Get(4), TaskItem(SLEEP, 4, false));
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 void RunTest_RecursivePosts(MessagePumpFactory factory) { 996 void RunTest_RecursivePosts(MessagePumpFactory factory) {
1012 const int kNumTimes = 1 << 17; 997 const int kNumTimes = 1 << 17;
1013 std::unique_ptr<MessagePump> pump(factory()); 998 std::unique_ptr<MessagePump> pump(factory());
1014 MessageLoop loop(std::move(pump)); 999 MessageLoop loop(std::move(pump));
1015 loop.PostTask(FROM_HERE, Bind(&PostNTasksThenQuit, kNumTimes)); 1000 loop.PostTask(FROM_HERE, Bind(&PostNTasksThenQuit, kNumTimes));
1016 loop.Run(); 1001 loop.Run();
1017 } 1002 }
1018 1003
1019 } // namespace test 1004 } // namespace test
1020 } // namespace base 1005 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/message_loop_test.h ('k') | ios/web/web_thread_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698