OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 time | 5 import time |
6 | 6 |
7 from telemetry.core import util | 7 from telemetry.core import util |
8 from telemetry.page.actions import wait | 8 from telemetry.page.actions import wait |
9 from telemetry.unittest import tab_test_case | 9 from telemetry.unittest import tab_test_case |
10 from telemetry.unittest import test | |
11 | 10 |
12 | 11 |
13 class WaitActionTest(tab_test_case.TabTestCase): | 12 class WaitActionTest(tab_test_case.TabTestCase): |
14 @test.Disabled('chromeos') | |
15 def testWaitAction(self): | 13 def testWaitAction(self): |
16 self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir()) | 14 self.Navigate('blank.html') |
17 self._tab.Navigate( | |
18 self._browser.http_server.UrlOf('blank.html')) | |
19 self._tab.WaitForDocumentReadyStateToBeComplete() | |
20 self.assertEquals( | 15 self.assertEquals( |
21 self._tab.EvaluateJavaScript('document.location.pathname;'), | 16 self._tab.EvaluateJavaScript('document.location.pathname;'), |
22 '/blank.html') | 17 '/blank.html') |
23 | 18 |
24 i = wait.WaitAction({ 'condition': 'duration', 'seconds': 1 }) | 19 i = wait.WaitAction({ 'condition': 'duration', 'seconds': 1 }) |
25 | 20 |
26 start_time = time.time() | 21 start_time = time.time() |
27 i.RunAction(None, self._tab, None) | 22 i.RunAction(None, self._tab, None) |
28 self.assertTrue(time.time() - start_time >= 1.0) | 23 self.assertTrue(time.time() - start_time >= 1.0) |
29 | 24 |
30 def testWaitActionTimeout(self): | 25 def testWaitActionTimeout(self): |
31 wait_action = wait.WaitAction({ | 26 wait_action = wait.WaitAction({ |
32 'condition': 'javascript', | 27 'condition': 'javascript', |
33 'javascript': '1 + 1 === 3', | 28 'javascript': '1 + 1 === 3', |
34 'timeout': 1 | 29 'timeout': 1 |
35 }) | 30 }) |
36 | 31 |
37 start_time = time.time() | 32 start_time = time.time() |
38 self.assertRaises( | 33 self.assertRaises( |
39 util.TimeoutException, | 34 util.TimeoutException, |
40 lambda: wait_action.RunAction(None, self._tab, None)) | 35 lambda: wait_action.RunAction(None, self._tab, None)) |
41 self.assertTrue(time.time() - start_time < 5) | 36 self.assertTrue(time.time() - start_time < 5) |
OLD | NEW |