- add sources.
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / page / actions / wait_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
5 import time
6
7 from telemetry.core import util
8 from telemetry.page.actions import wait
9 from telemetry.unittest import tab_test_case
10
11 class WaitActionTest(tab_test_case.TabTestCase):
12   def testWaitAction(self):
13     self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir())
14     self._tab.Navigate(
15       self._browser.http_server.UrlOf('blank.html'))
16     self._tab.WaitForDocumentReadyStateToBeComplete()
17     self.assertEquals(
18         self._tab.EvaluateJavaScript('document.location.pathname;'),
19         '/blank.html')
20
21     i = wait.WaitAction({ 'condition': 'duration', 'seconds': 1 })
22
23     start_time = time.time()
24     i.RunAction(None, self._tab, None)
25     self.assertAlmostEqual(time.time() - start_time, 1, places=1)
26
27   def testWaitActionTimeout(self):
28     wait_action = wait.WaitAction({
29       'condition': 'javascript',
30       'javascript': '1 + 1 === 3',
31       'timeout': 1
32     })
33
34     start_time = time.time()
35     self.assertRaises(
36         util.TimeoutException,
37         lambda: wait_action.RunAction(None, self._tab, None))
38     self.assertTrue(time.time() - start_time < 5)