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

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

Issue 588593002: mojo: Allow basic RunLoop to be quit from a posted task. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Follow review Created 6 years, 3 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
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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 run_loop.PostDelayedTask(Closure(Task(2, &sequence)), 0); 406 run_loop.PostDelayedTask(Closure(Task(2, &sequence)), 0);
407 run_loop.PostDelayedTask(Closure(Task(3, &sequence)), 0); 407 run_loop.PostDelayedTask(Closure(Task(3, &sequence)), 0);
408 run_loop.RunUntilIdle(); 408 run_loop.RunUntilIdle();
409 409
410 ASSERT_EQ(3u, sequence.size()); 410 ASSERT_EQ(3u, sequence.size());
411 EXPECT_EQ(1, sequence[0]); 411 EXPECT_EQ(1, sequence[0]);
412 EXPECT_EQ(2, sequence[1]); 412 EXPECT_EQ(2, sequence[1]);
413 EXPECT_EQ(3, sequence[2]); 413 EXPECT_EQ(3, sequence[2]);
414 } 414 }
415 415
416 struct QuittingTask {
417 QuittingTask(RunLoop* run_loop) : run_loop(run_loop) {}
418
419 void Run() const { run_loop->Quit(); }
420
421 RunLoop* run_loop;
422 };
423
424 TEST_F(RunLoopTest, QuitFromDelayedTask) {
425 TestRunLoopHandler handler;
426 MessagePipe test_pipe;
427 RunLoop run_loop;
428 run_loop.AddHandler(&handler,
429 test_pipe.handle0.get(),
430 MOJO_HANDLE_SIGNAL_READABLE,
431 MOJO_DEADLINE_INDEFINITE);
432 run_loop.PostDelayedTask(Closure(QuittingTask(&run_loop)), 0);
433 run_loop.Run();
434 }
435
416 } // namespace 436 } // namespace
417 } // namespace mojo 437 } // namespace mojo
OLDNEW
« mojo/public/cpp/utility/lib/run_loop.cc ('K') | « mojo/public/cpp/utility/run_loop.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698