| 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 def _Increment(array): | |
| 12 def _Closure(): | |
| 13 array.append(0) | |
| 14 return _Closure | |
| 15 | |
| 16 | |
| 17 class RunLoopTest(mojo_unittest.MojoTestCase): | |
| 18 | |
| 19 def testRunLoop(self): | |
| 20 array = [] | |
| 21 for _ in xrange(10): | |
| 22 self.loop.PostDelayedTask(_Increment(array)) | |
| 23 self.loop.RunUntilIdle() | |
| 24 self.assertEquals(len(array), 10) | |
| 25 | |
| 26 def testRunLoopWithException(self): | |
| 27 def Throw(): | |
| 28 raise Exception("error") | |
| 29 array = [] | |
| 30 self.loop.PostDelayedTask(Throw) | |
| 31 self.loop.PostDelayedTask(_Increment(array)) | |
| 32 with self.assertRaisesRegexp(Exception, '^error$'): | |
| 33 self.loop.Run() | |
| 34 self.assertEquals(len(array), 0) | |
| 35 self.loop.RunUntilIdle() | |
| 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 |