| OLD | NEW |
| (Empty) |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import mojo_unittest | |
| 6 | |
| 7 # pylint: disable=E0611 | |
| 8 from mojo import system | |
| 9 | |
| 10 | |
| 11 class AsyncWaitTest(mojo_unittest.MojoTestCase): | |
| 12 | |
| 13 def setUp(self): | |
| 14 super(AsyncWaitTest, self).setUp() | |
| 15 self.array = [] | |
| 16 self.handles = system.MessagePipe() | |
| 17 self.cancel = self.handles.handle0.AsyncWait(system.HANDLE_SIGNAL_READABLE, | |
| 18 system.DEADLINE_INDEFINITE, | |
| 19 self._OnResult) | |
| 20 | |
| 21 def tearDown(self): | |
| 22 self.cancel() | |
| 23 self.handles = None | |
| 24 self.array = None | |
| 25 super(AsyncWaitTest, self).tearDown() | |
| 26 | |
| 27 def _OnResult(self, value): | |
| 28 self.array.append(value) | |
| 29 | |
| 30 def _WriteToHandle(self): | |
| 31 self.handles.handle1.WriteMessage() | |
| 32 | |
| 33 def _PostWriteAndRun(self): | |
| 34 self.loop.PostDelayedTask(self._WriteToHandle, 0) | |
| 35 self.loop.RunUntilIdle() | |
| 36 | |
| 37 def testAsyncWait(self): | |
| 38 self._PostWriteAndRun() | |
| 39 self.assertEquals(len(self.array), 1) | |
| 40 self.assertEquals(system.RESULT_OK, self.array[0]) | |
| 41 | |
| 42 def testAsyncWaitCancel(self): | |
| 43 self.loop.PostDelayedTask(self.cancel, 0) | |
| 44 self._PostWriteAndRun() | |
| 45 self.assertEquals(len(self.array), 0) | |
| 46 | |
| 47 def testAsyncWaitImmediateCancel(self): | |
| 48 self.cancel() | |
| 49 self._PostWriteAndRun() | |
| 50 self.assertEquals(len(self.array), 0) | |
| OLD | NEW |