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

Side by Side Diff: base/task_runner_util_unittest.cc

Issue 12226007: base: Convert the remaining uses of MessageLoop::RunUntilIdle to RunLoop variant. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win Created 7 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 | « base/system_monitor/system_monitor_unittest.cc ('k') | no next file » | 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) 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 "base/task_runner_util.h" 5 #include "base/task_runner_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/run_loop.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 namespace base { 12 namespace base {
12 13
13 namespace { 14 namespace {
14 15
15 int ReturnFourtyTwo() { 16 int ReturnFourtyTwo() {
16 return 42; 17 return 42;
17 } 18 }
18 19
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 void ExpectScopedFoo(scoped_ptr_malloc<Foo, FreeFooFunctor> foo) { 59 void ExpectScopedFoo(scoped_ptr_malloc<Foo, FreeFooFunctor> foo) {
59 EXPECT_TRUE(foo.get()); 60 EXPECT_TRUE(foo.get());
60 scoped_ptr_malloc<Foo, FreeFooFunctor> local_foo(foo.Pass()); 61 scoped_ptr_malloc<Foo, FreeFooFunctor> local_foo(foo.Pass());
61 EXPECT_TRUE(local_foo.get()); 62 EXPECT_TRUE(local_foo.get());
62 EXPECT_FALSE(foo.get()); 63 EXPECT_FALSE(foo.get());
63 } 64 }
64 65
65 } // namespace 66 } // namespace
66 67
67 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResult) { 68 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResult) {
68 MessageLoop message_loop;
69 int result = 0; 69 int result = 0;
70 70
71 PostTaskAndReplyWithResult( 71 MessageLoop message_loop;
72 message_loop.message_loop_proxy(), 72 PostTaskAndReplyWithResult(message_loop.message_loop_proxy(),
73 FROM_HERE, 73 FROM_HERE,
74 Bind(&ReturnFourtyTwo), 74 Bind(&ReturnFourtyTwo),
75 Bind(&StoreValue, &result)); 75 Bind(&StoreValue, &result));
76 76
77 message_loop.RunUntilIdle(); 77 RunLoop().RunUntilIdle();
78 78
79 EXPECT_EQ(42, result); 79 EXPECT_EQ(42, result);
80 } 80 }
81 81
82 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultImplicitConvert) { 82 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultImplicitConvert) {
83 MessageLoop message_loop;
84 double result = 0; 83 double result = 0;
85 84
86 PostTaskAndReplyWithResult( 85 MessageLoop message_loop;
87 message_loop.message_loop_proxy(), 86 PostTaskAndReplyWithResult(message_loop.message_loop_proxy(),
88 FROM_HERE, 87 FROM_HERE,
89 Bind(&ReturnFourtyTwo), 88 Bind(&ReturnFourtyTwo),
90 Bind(&StoreDoubleValue, &result)); 89 Bind(&StoreDoubleValue, &result));
91 90
92 message_loop.RunUntilIdle(); 91 RunLoop().RunUntilIdle();
93 92
94 EXPECT_DOUBLE_EQ(42.0, result); 93 EXPECT_DOUBLE_EQ(42.0, result);
95 } 94 }
96 95
97 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassed) { 96 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassed) {
98 g_foo_destruct_count = 0; 97 g_foo_destruct_count = 0;
99 g_foo_free_count = 0; 98 g_foo_free_count = 0;
100 99
101 MessageLoop message_loop; 100 MessageLoop message_loop;
101 PostTaskAndReplyWithResult(message_loop.message_loop_proxy(),
102 FROM_HERE,
103 Bind(&CreateFoo),
104 Bind(&ExpectFoo));
102 105
103 PostTaskAndReplyWithResult( 106 RunLoop().RunUntilIdle();
104 message_loop.message_loop_proxy(),
105 FROM_HERE,
106 Bind(&CreateFoo),
107 Bind(&ExpectFoo));
108
109 message_loop.RunUntilIdle();
110 107
111 EXPECT_EQ(1, g_foo_destruct_count); 108 EXPECT_EQ(1, g_foo_destruct_count);
112 EXPECT_EQ(0, g_foo_free_count); 109 EXPECT_EQ(0, g_foo_free_count);
113 } 110 }
114 111
115 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassedFreeProc) { 112 TEST(TaskRunnerHelpersTest, PostTaskAndReplyWithResultPassedFreeProc) {
116 g_foo_destruct_count = 0; 113 g_foo_destruct_count = 0;
117 g_foo_free_count = 0; 114 g_foo_free_count = 0;
118 115
119 MessageLoop message_loop; 116 MessageLoop message_loop;
117 PostTaskAndReplyWithResult(message_loop.message_loop_proxy(),
118 FROM_HERE,
119 Bind(&CreateScopedFoo),
120 Bind(&ExpectScopedFoo));
120 121
121 PostTaskAndReplyWithResult( 122 RunLoop().RunUntilIdle();
122 message_loop.message_loop_proxy(),
123 FROM_HERE,
124 Bind(&CreateScopedFoo),
125 Bind(&ExpectScopedFoo));
126
127 message_loop.RunUntilIdle();
128 123
129 EXPECT_EQ(1, g_foo_destruct_count); 124 EXPECT_EQ(1, g_foo_destruct_count);
130 EXPECT_EQ(1, g_foo_free_count); 125 EXPECT_EQ(1, g_foo_free_count);
131 } 126 }
132 127
133 } // namespace base 128 } // namespace base
OLDNEW
« no previous file with comments | « base/system_monitor/system_monitor_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698