| OLD | NEW |
| 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 "mojo/public/utility/run_loop.h" | 5 #include "mojo/public/utility/run_loop.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "mojo/public/system/core_cpp.h" | 9 #include "mojo/public/system/core_cpp.h" |
| 10 #include "mojo/public/tests/test_support.h" | 10 #include "mojo/public/tests/test_support.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 MessagePipe test_pipe; | 98 MessagePipe test_pipe; |
| 99 EXPECT_EQ(MOJO_RESULT_OK, test::WriteEmptyMessage(test_pipe.handle1.get())); | 99 EXPECT_EQ(MOJO_RESULT_OK, test::WriteEmptyMessage(test_pipe.handle1.get())); |
| 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_WAIT_FLAG_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 } | 109 } |
| 109 | 110 |
| 110 class QuitOnReadyRunLoopHandler : public TestRunLoopHandler { | 111 class QuitOnReadyRunLoopHandler : public TestRunLoopHandler { |
| 111 public: | 112 public: |
| 112 QuitOnReadyRunLoopHandler() : run_loop_(NULL) { | 113 QuitOnReadyRunLoopHandler() : run_loop_(NULL) { |
| 113 } | 114 } |
| 114 virtual ~QuitOnReadyRunLoopHandler() {} | 115 virtual ~QuitOnReadyRunLoopHandler() {} |
| 115 | 116 |
| 116 void set_run_loop(RunLoop* run_loop) { run_loop_ = run_loop; } | 117 void set_run_loop(RunLoop* run_loop) { run_loop_ = run_loop; } |
| 117 | 118 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 133 MessagePipe test_pipe; | 134 MessagePipe test_pipe; |
| 134 EXPECT_EQ(MOJO_RESULT_OK, test::WriteEmptyMessage(test_pipe.handle1.get())); | 135 EXPECT_EQ(MOJO_RESULT_OK, test::WriteEmptyMessage(test_pipe.handle1.get())); |
| 135 | 136 |
| 136 RunLoop run_loop; | 137 RunLoop run_loop; |
| 137 handler.set_run_loop(&run_loop); | 138 handler.set_run_loop(&run_loop); |
| 138 run_loop.AddHandler(&handler, test_pipe.handle0.get(), | 139 run_loop.AddHandler(&handler, test_pipe.handle0.get(), |
| 139 MOJO_WAIT_FLAG_READABLE, MOJO_DEADLINE_INDEFINITE); | 140 MOJO_WAIT_FLAG_READABLE, MOJO_DEADLINE_INDEFINITE); |
| 140 run_loop.Run(); | 141 run_loop.Run(); |
| 141 EXPECT_EQ(1, handler.ready_count()); | 142 EXPECT_EQ(1, handler.ready_count()); |
| 142 EXPECT_EQ(0, handler.error_count()); | 143 EXPECT_EQ(0, handler.error_count()); |
| 144 EXPECT_TRUE(run_loop.HasHandler(test_pipe.handle0.get())); |
| 143 } | 145 } |
| 144 | 146 |
| 145 class QuitOnErrorRunLoopHandler : public TestRunLoopHandler { | 147 class QuitOnErrorRunLoopHandler : public TestRunLoopHandler { |
| 146 public: | 148 public: |
| 147 QuitOnErrorRunLoopHandler() : run_loop_(NULL) { | 149 QuitOnErrorRunLoopHandler() : run_loop_(NULL) { |
| 148 } | 150 } |
| 149 virtual ~QuitOnErrorRunLoopHandler() {} | 151 virtual ~QuitOnErrorRunLoopHandler() {} |
| 150 | 152 |
| 151 void set_run_loop(RunLoop* run_loop) { run_loop_ = run_loop; } | 153 void set_run_loop(RunLoop* run_loop) { run_loop_ = run_loop; } |
| 152 | 154 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 168 MessagePipe test_pipe; | 170 MessagePipe test_pipe; |
| 169 RunLoop run_loop; | 171 RunLoop run_loop; |
| 170 handler.set_run_loop(&run_loop); | 172 handler.set_run_loop(&run_loop); |
| 171 run_loop.AddHandler(&handler, test_pipe.handle0.get(), | 173 run_loop.AddHandler(&handler, test_pipe.handle0.get(), |
| 172 MOJO_WAIT_FLAG_READABLE, | 174 MOJO_WAIT_FLAG_READABLE, |
| 173 static_cast<MojoDeadline>(10000)); | 175 static_cast<MojoDeadline>(10000)); |
| 174 run_loop.Run(); | 176 run_loop.Run(); |
| 175 EXPECT_EQ(0, handler.ready_count()); | 177 EXPECT_EQ(0, handler.ready_count()); |
| 176 EXPECT_EQ(1, handler.error_count()); | 178 EXPECT_EQ(1, handler.error_count()); |
| 177 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, handler.last_error_result()); | 179 EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, handler.last_error_result()); |
| 180 EXPECT_FALSE(run_loop.HasHandler(test_pipe.handle0.get())); |
| 178 } | 181 } |
| 179 | 182 |
| 180 TEST_F(RunLoopTest, Current) { | 183 TEST_F(RunLoopTest, Current) { |
| 181 EXPECT_TRUE(RunLoop::current() == NULL); | 184 EXPECT_TRUE(RunLoop::current() == NULL); |
| 182 { | 185 { |
| 183 RunLoop run_loop; | 186 RunLoop run_loop; |
| 184 EXPECT_EQ(&run_loop, RunLoop::current()); | 187 EXPECT_EQ(&run_loop, RunLoop::current()); |
| 185 } | 188 } |
| 186 EXPECT_TRUE(RunLoop::current() == NULL); | 189 EXPECT_TRUE(RunLoop::current() == NULL); |
| 187 } | 190 } |
| 188 | 191 |
| 189 } // namespace | 192 } // namespace |
| 190 } // namespace utility | 193 } // namespace utility |
| 191 } // namespace mojo | 194 } // namespace mojo |
| OLD | NEW |