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

Side by Side Diff: mojo/public/cpp/utility/tests/run_loop_unittest.cc

Issue 336313007: Mojo: Rename MOJO_WAIT_FLAG_... -> MOJO_HANDLE_SIGNAL_.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 6 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 | « mojo/public/cpp/utility/run_loop.h ('k') | mojo/public/js/bindings/connector.js » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/public/cpp/utility/run_loop.h" 5 #include "mojo/public/cpp/utility/run_loop.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "mojo/public/cpp/system/core.h" 9 #include "mojo/public/cpp/system/core.h"
10 #include "mojo/public/cpp/test_support/test_utils.h" 10 #include "mojo/public/cpp/test_support/test_utils.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 // Verifies RunLoop quits when no more handles (handle is removed when ready). 95 // Verifies RunLoop quits when no more handles (handle is removed when ready).
96 TEST_F(RunLoopTest, HandleReady) { 96 TEST_F(RunLoopTest, HandleReady) {
97 RemoveOnReadyRunLoopHandler handler; 97 RemoveOnReadyRunLoopHandler handler;
98 MessagePipe test_pipe; 98 MessagePipe test_pipe;
99 EXPECT_TRUE(test::WriteTextMessage(test_pipe.handle1.get(), std::string())); 99 EXPECT_TRUE(test::WriteTextMessage(test_pipe.handle1.get(), std::string()));
100 100
101 RunLoop run_loop; 101 RunLoop run_loop;
102 handler.set_run_loop(&run_loop); 102 handler.set_run_loop(&run_loop);
103 run_loop.AddHandler(&handler, test_pipe.handle0.get(), 103 run_loop.AddHandler(&handler, test_pipe.handle0.get(),
104 MOJO_WAIT_FLAG_READABLE, MOJO_DEADLINE_INDEFINITE); 104 MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE);
105 run_loop.Run(); 105 run_loop.Run();
106 EXPECT_EQ(1, handler.ready_count()); 106 EXPECT_EQ(1, handler.ready_count());
107 EXPECT_EQ(0, handler.error_count()); 107 EXPECT_EQ(0, handler.error_count());
108 EXPECT_FALSE(run_loop.HasHandler(test_pipe.handle0.get())); 108 EXPECT_FALSE(run_loop.HasHandler(test_pipe.handle0.get()));
109 } 109 }
110 110
111 class QuitOnReadyRunLoopHandler : public TestRunLoopHandler { 111 class QuitOnReadyRunLoopHandler : public TestRunLoopHandler {
112 public: 112 public:
113 QuitOnReadyRunLoopHandler() : run_loop_(NULL) { 113 QuitOnReadyRunLoopHandler() : run_loop_(NULL) {
114 } 114 }
(...skipping 15 matching lines...) Expand all
130 130
131 // Verifies Quit() from OnHandleReady() quits the loop. 131 // Verifies Quit() from OnHandleReady() quits the loop.
132 TEST_F(RunLoopTest, QuitFromReady) { 132 TEST_F(RunLoopTest, QuitFromReady) {
133 QuitOnReadyRunLoopHandler handler; 133 QuitOnReadyRunLoopHandler handler;
134 MessagePipe test_pipe; 134 MessagePipe test_pipe;
135 EXPECT_TRUE(test::WriteTextMessage(test_pipe.handle1.get(), std::string())); 135 EXPECT_TRUE(test::WriteTextMessage(test_pipe.handle1.get(), std::string()));
136 136
137 RunLoop run_loop; 137 RunLoop run_loop;
138 handler.set_run_loop(&run_loop); 138 handler.set_run_loop(&run_loop);
139 run_loop.AddHandler(&handler, test_pipe.handle0.get(), 139 run_loop.AddHandler(&handler, test_pipe.handle0.get(),
140 MOJO_WAIT_FLAG_READABLE, MOJO_DEADLINE_INDEFINITE); 140 MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE);
141 run_loop.Run(); 141 run_loop.Run();
142 EXPECT_EQ(1, handler.ready_count()); 142 EXPECT_EQ(1, handler.ready_count());
143 EXPECT_EQ(0, handler.error_count()); 143 EXPECT_EQ(0, handler.error_count());
144 EXPECT_TRUE(run_loop.HasHandler(test_pipe.handle0.get())); 144 EXPECT_TRUE(run_loop.HasHandler(test_pipe.handle0.get()));
145 } 145 }
146 146
147 class QuitOnErrorRunLoopHandler : public TestRunLoopHandler { 147 class QuitOnErrorRunLoopHandler : public TestRunLoopHandler {
148 public: 148 public:
149 QuitOnErrorRunLoopHandler() : run_loop_(NULL) { 149 QuitOnErrorRunLoopHandler() : run_loop_(NULL) {
150 } 150 }
(...skipping 14 matching lines...) Expand all
165 MOJO_DISALLOW_COPY_AND_ASSIGN(QuitOnErrorRunLoopHandler); 165 MOJO_DISALLOW_COPY_AND_ASSIGN(QuitOnErrorRunLoopHandler);
166 }; 166 };
167 167
168 // Verifies Quit() when the deadline is reached works. 168 // Verifies Quit() when the deadline is reached works.
169 TEST_F(RunLoopTest, QuitWhenDeadlineExpired) { 169 TEST_F(RunLoopTest, QuitWhenDeadlineExpired) {
170 QuitOnErrorRunLoopHandler handler; 170 QuitOnErrorRunLoopHandler handler;
171 MessagePipe test_pipe; 171 MessagePipe test_pipe;
172 RunLoop run_loop; 172 RunLoop run_loop;
173 handler.set_run_loop(&run_loop); 173 handler.set_run_loop(&run_loop);
174 run_loop.AddHandler(&handler, test_pipe.handle0.get(), 174 run_loop.AddHandler(&handler, test_pipe.handle0.get(),
175 MOJO_WAIT_FLAG_READABLE, 175 MOJO_HANDLE_SIGNAL_READABLE,
176 static_cast<MojoDeadline>(10000)); 176 static_cast<MojoDeadline>(10000));
177 run_loop.Run(); 177 run_loop.Run();
178 EXPECT_EQ(0, handler.ready_count()); 178 EXPECT_EQ(0, handler.ready_count());
179 EXPECT_EQ(1, handler.error_count()); 179 EXPECT_EQ(1, handler.error_count());
180 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, handler.last_error_result()); 180 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, handler.last_error_result());
181 EXPECT_FALSE(run_loop.HasHandler(test_pipe.handle0.get())); 181 EXPECT_FALSE(run_loop.HasHandler(test_pipe.handle0.get()));
182 } 182 }
183 183
184 TEST_F(RunLoopTest, Current) { 184 TEST_F(RunLoopTest, Current) {
185 EXPECT_TRUE(RunLoop::current() == NULL); 185 EXPECT_TRUE(RunLoop::current() == NULL);
186 { 186 {
187 RunLoop run_loop; 187 RunLoop run_loop;
188 EXPECT_EQ(&run_loop, RunLoop::current()); 188 EXPECT_EQ(&run_loop, RunLoop::current());
189 } 189 }
190 EXPECT_TRUE(RunLoop::current() == NULL); 190 EXPECT_TRUE(RunLoop::current() == NULL);
191 } 191 }
192 192
193 // TODO(darin): Add tests for nested calls to RunLoop::Run(). See crbug/384633. 193 // TODO(darin): Add tests for nested calls to RunLoop::Run(). See crbug/384633.
194 194
195 } // namespace 195 } // namespace
196 } // namespace mojo 196 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/utility/run_loop.h ('k') | mojo/public/js/bindings/connector.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698