- add sources.
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / util_unittest.py
1 # Copyright (c) 2012 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 import unittest
5
6 from telemetry.core import util
7
8 class TestWait(unittest.TestCase):
9   @staticmethod
10   def testNonTimeout():
11     def test():
12       return True
13     util.WaitFor(test, 0.1)
14
15   def testTimeout(self):
16     def test():
17       return False
18     self.assertRaises(util.TimeoutException, lambda: util.WaitFor(test, 0.1))
19
20   def testCallable(self):
21     """Test methods and anonymous functions, functions are tested elsewhere."""
22     class Test(object):
23       def Method(self):
24         return 'test'
25     util.WaitFor(Test().Method, 0.1)
26
27     util.WaitFor(lambda: 1, 0.1)
28
29     # Test noncallable condition.
30     self.assertRaises(TypeError, lambda: util.WaitFor('test', 0.1))
31
32   def testReturn(self):
33     self.assertEquals('test', util.WaitFor(lambda: 'test', 0.1))