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

Side by Side Diff: base/message_loop_unittest.cc

Issue 14387002: Adding TryPostTask to the message loop (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix bool Created 7 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 MessageLoop::current()->PostTask(FROM_HERE, Bind( 86 MessageLoop::current()->PostTask(FROM_HERE, Bind(
87 &Foo::Test0, foo.get())); 87 &Foo::Test0, foo.get()));
88 MessageLoop::current()->PostTask(FROM_HERE, Bind( 88 MessageLoop::current()->PostTask(FROM_HERE, Bind(
89 &Foo::Test1ConstRef, foo.get(), a)); 89 &Foo::Test1ConstRef, foo.get(), a));
90 MessageLoop::current()->PostTask(FROM_HERE, Bind( 90 MessageLoop::current()->PostTask(FROM_HERE, Bind(
91 &Foo::Test1Ptr, foo.get(), &b)); 91 &Foo::Test1Ptr, foo.get(), &b));
92 MessageLoop::current()->PostTask(FROM_HERE, Bind( 92 MessageLoop::current()->PostTask(FROM_HERE, Bind(
93 &Foo::Test1Int, foo.get(), 100)); 93 &Foo::Test1Int, foo.get(), 100));
94 MessageLoop::current()->PostTask(FROM_HERE, Bind( 94 MessageLoop::current()->PostTask(FROM_HERE, Bind(
95 &Foo::Test2Ptr, foo.get(), &a, &c)); 95 &Foo::Test2Ptr, foo.get(), &a, &c));
96 MessageLoop::current()->PostTask(FROM_HERE, Bind( 96
97 &Foo::Test2Mixed, foo.get(), a, &d)); 97 EXPECT_TRUE(MessageLoop::current()->TryPostTask(FROM_HERE, Bind(
jar (doing other things) 2013/04/26 21:59:43 You should probably add a test that holds the lock
98 &Foo::Test2Mixed, foo.get(), a, &d)));
98 99
99 // After all tests, post a message that will shut down the message loop 100 // After all tests, post a message that will shut down the message loop
100 MessageLoop::current()->PostTask(FROM_HERE, Bind( 101 MessageLoop::current()->PostTask(FROM_HERE, Bind(
101 &MessageLoop::Quit, Unretained(MessageLoop::current()))); 102 &MessageLoop::Quit, Unretained(MessageLoop::current())));
102 103
103 // Now kick things off 104 // Now kick things off
104 MessageLoop::current()->Run(); 105 MessageLoop::current()->Run();
105 106
106 EXPECT_EQ(foo->test_count(), 105); 107 EXPECT_EQ(foo->test_count(), 105);
107 EXPECT_EQ(foo->result(), "abacad"); 108 EXPECT_EQ(foo->result(), "abacad");
(...skipping 1965 matching lines...) Expand 10 before | Expand all | Expand 10 after
2073 // On Linux, the pipe buffer size is 64KiB by default. The bug caused one 2074 // On Linux, the pipe buffer size is 64KiB by default. The bug caused one
2074 // byte accumulated in the pipe per two posts, so we should repeat 128K 2075 // byte accumulated in the pipe per two posts, so we should repeat 128K
2075 // times to reproduce the bug. 2076 // times to reproduce the bug.
2076 const int kNumTimes = 1 << 17; 2077 const int kNumTimes = 1 << 17;
2077 RunTest_RecursivePosts(MessageLoop::TYPE_DEFAULT, kNumTimes); 2078 RunTest_RecursivePosts(MessageLoop::TYPE_DEFAULT, kNumTimes);
2078 RunTest_RecursivePosts(MessageLoop::TYPE_UI, kNumTimes); 2079 RunTest_RecursivePosts(MessageLoop::TYPE_UI, kNumTimes);
2079 RunTest_RecursivePosts(MessageLoop::TYPE_IO, kNumTimes); 2080 RunTest_RecursivePosts(MessageLoop::TYPE_IO, kNumTimes);
2080 } 2081 }
2081 2082
2082 } // namespace base 2083 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698