Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: mojo/python/tests/async_wait_unittest.py

Issue 644773002: mojo: Add RunLoop::Current() and refactor unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 class AsyncWaitTest(unittest.TestCase): 11 class AsyncWaitTest(mojo_unittest.MojoTestCase):
13 12
14 def setUp(self): 13 def setUp(self):
15 mojo.embedder.Init() 14 super(AsyncWaitTest, self).setUp()
16 self.loop = system.RunLoop()
17 self.array = [] 15 self.array = []
18 self.handles = system.MessagePipe() 16 self.handles = system.MessagePipe()
19 self.cancel = self.handles.handle0.AsyncWait(system.HANDLE_SIGNAL_READABLE, 17 self.cancel = self.handles.handle0.AsyncWait(system.HANDLE_SIGNAL_READABLE,
20 system.DEADLINE_INDEFINITE, 18 system.DEADLINE_INDEFINITE,
21 self._OnResult) 19 self._OnResult)
22 20
23 def tearDown(self): 21 def tearDown(self):
24 self.cancel() 22 self.cancel()
25 self.handles = None 23 self.handles = None
26 self.array = None 24 self.array = None
27 self.loop = None 25 super(AsyncWaitTest, self).tearDown()
28 26
29 def _OnResult(self, value): 27 def _OnResult(self, value):
30 self.array.append(value) 28 self.array.append(value)
31 29
32 def _WriteToHandle(self): 30 def _WriteToHandle(self):
33 self.handles.handle1.WriteMessage() 31 self.handles.handle1.WriteMessage()
34 32
35 def _PostWriteAndRun(self): 33 def _PostWriteAndRun(self):
36 self.loop.PostDelayedTask(self._WriteToHandle, 0) 34 self.loop.PostDelayedTask(self._WriteToHandle, 0)
37 self.loop.RunUntilIdle() 35 self.loop.RunUntilIdle()
38 36
39 def testAsyncWait(self): 37 def testAsyncWait(self):
40 self._PostWriteAndRun() 38 self._PostWriteAndRun()
41 self.assertEquals(len(self.array), 1) 39 self.assertEquals(len(self.array), 1)
42 self.assertEquals(system.RESULT_OK, self.array[0]) 40 self.assertEquals(system.RESULT_OK, self.array[0])
43 41
44 def testAsyncWaitCancel(self): 42 def testAsyncWaitCancel(self):
45 self.loop.PostDelayedTask(self.cancel, 0) 43 self.loop.PostDelayedTask(self.cancel, 0)
46 self._PostWriteAndRun() 44 self._PostWriteAndRun()
47 self.assertEquals(len(self.array), 0) 45 self.assertEquals(len(self.array), 0)
48 46
49 def testAsyncWaitImmediateCancel(self): 47 def testAsyncWaitImmediateCancel(self):
50 self.cancel() 48 self.cancel()
51 self._PostWriteAndRun() 49 self._PostWriteAndRun()
52 self.assertEquals(len(self.array), 0) 50 self.assertEquals(len(self.array), 0)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698