| OLD | NEW |
| 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 import unittest | 5 import mojo_unittest |
| 6 | 6 |
| 7 # pylint: disable=F0401 | 7 # pylint: disable=F0401 |
| 8 import mojo.embedder | |
| 9 from mojo import system | 8 from mojo import system |
| 10 | 9 |
| 11 | 10 |
| 12 def _Increment(array): | 11 def _Increment(array): |
| 13 def _Closure(): | 12 def _Closure(): |
| 14 array.append(0) | 13 array.append(0) |
| 15 return _Closure | 14 return _Closure |
| 16 | 15 |
| 17 | 16 |
| 18 class RunLoopTest(unittest.TestCase): | 17 class RunLoopTest(mojo_unittest.MojoTestCase): |
| 19 | |
| 20 def setUp(self): | |
| 21 mojo.embedder.Init() | |
| 22 | 18 |
| 23 def testRunLoop(self): | 19 def testRunLoop(self): |
| 24 loop = system.RunLoop() | |
| 25 array = [] | 20 array = [] |
| 26 for _ in xrange(10): | 21 for _ in xrange(10): |
| 27 loop.PostDelayedTask(_Increment(array)) | 22 self.loop.PostDelayedTask(_Increment(array)) |
| 28 loop.RunUntilIdle() | 23 self.loop.RunUntilIdle() |
| 29 self.assertEquals(len(array), 10) | 24 self.assertEquals(len(array), 10) |
| 30 | 25 |
| 31 def testRunLoopWithException(self): | 26 def testRunLoopWithException(self): |
| 32 loop = system.RunLoop() | |
| 33 def Throw(): | 27 def Throw(): |
| 34 raise Exception("error") | 28 raise Exception("error") |
| 35 array = [] | 29 array = [] |
| 36 loop.PostDelayedTask(Throw) | 30 self.loop.PostDelayedTask(Throw) |
| 37 loop.PostDelayedTask(_Increment(array)) | 31 self.loop.PostDelayedTask(_Increment(array)) |
| 38 with self.assertRaisesRegexp(Exception, '^error$'): | 32 with self.assertRaisesRegexp(Exception, '^error$'): |
| 39 loop.Run() | 33 self.loop.Run() |
| 40 self.assertEquals(len(array), 0) | 34 self.assertEquals(len(array), 0) |
| 41 loop.RunUntilIdle() | 35 self.loop.RunUntilIdle() |
| 42 self.assertEquals(len(array), 1) | 36 self.assertEquals(len(array), 1) |
| 37 |
| 38 def testCurrent(self): |
| 39 self.assertEquals(system.RunLoop.Current(), self.loop) |
| 40 self.loop = None |
| 41 self.assertIsNone(system.RunLoop.Current()) |
| OLD | NEW |