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 unittest |
| 6 |
| 7 # pylint: disable=F0401 |
| 8 import mojo.embedder |
| 9 from mojo import system |
| 10 |
| 11 |
| 12 class AsyncWaitTest(unittest.TestCase): |
| 13 |
| 14 def setUp(self): |
| 15 mojo.embedder.Init() |
| 16 self.loop = system.RunLoop() |
| 17 self.array = [] |
| 18 self.handles = system.MessagePipe() |
| 19 self.cancel = self.handles.handle0.AsyncWait(system.HANDLE_SIGNAL_READABLE, |
| 20 system.DEADLINE_INDEFINITE, |
| 21 self.OnResult) |
| 22 self.loop.PostDelayedTask(self.WriteToHandle, 100) |
| 23 |
| 24 def tearDown(self): |
| 25 self.handles = None |
| 26 self.array = None |
| 27 self.loop = None |
| 28 |
| 29 def OnResult(self, value): |
| 30 self.array.append(value) |
| 31 |
| 32 def WriteToHandle(self): |
| 33 self.handles.handle1.WriteMessage() |
| 34 |
| 35 def testAsyncWait(self): |
| 36 self.loop.RunUntilIdle() |
| 37 self.assertEquals(len(self.array), 1) |
| 38 self.assertEquals(system.RESULT_OK, self.array[0]) |
| 39 self.cancel() |
| 40 |
| 41 def testAsyncWaitCancel(self): |
| 42 self.loop.PostDelayedTask(self.cancel, 50) |
| 43 self.loop.RunUntilIdle() |
| 44 self.assertEquals(len(self.array), 0) |
| 45 self.cancel() |
| 46 |
| 47 def testAsyncWaitImmediateCancel(self): |
| 48 self.cancel() |
| 49 self.loop.RunUntilIdle() |
| 50 self.assertEquals(len(self.array), 0) |
| 51 self.cancel() |
OLD | NEW |