OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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.internal.actions import page_action | 7 from telemetry.internal.actions import page_action |
8 | 8 |
9 | 9 |
10 class NavigateAction(page_action.PageAction): | 10 class NavigateAction(page_action.PageAction): |
11 def __init__(self, url, script_to_evaluate_on_commit=None, | 11 def __init__(self, url, script_to_evaluate_on_commit=None, |
12 timeout_in_seconds=60): | 12 timeout_in_seconds=60): |
13 super(NavigateAction, self).__init__() | 13 super(NavigateAction, self).__init__() |
14 assert url, 'Must specify url for navigate action' | 14 assert url, 'Must specify url for navigate action' |
15 self._url = url | 15 self._url = url |
16 self._script_to_evaluate_on_commit = script_to_evaluate_on_commit | 16 self._script_to_evaluate_on_commit = script_to_evaluate_on_commit |
17 self._timeout_in_seconds = timeout_in_seconds | 17 self._timeout_in_seconds = timeout_in_seconds |
18 | 18 |
19 def RunAction(self, tab): | 19 def RunAction(self, tab): |
20 start_time = time.time() | 20 start_time = time.time() |
21 tab.Navigate(self._url, | 21 tab.Navigate(self._url, |
22 self._script_to_evaluate_on_commit, | 22 self._script_to_evaluate_on_commit, |
23 self._timeout_in_seconds) | 23 self._timeout_in_seconds) |
24 | 24 |
25 time_left_in_seconds = (start_time + self._timeout_in_seconds | 25 time_left_in_seconds = (start_time + self._timeout_in_seconds \ |
26 - time.time()) | 26 - time.time()) |
27 time_left_in_seconds = max(0, time_left_in_seconds) | 27 time_left_in_seconds = max(0, time_left_in_seconds) |
28 tab.WaitForDocumentReadyStateToBeInteractiveOrBetter( | 28 tab.WaitForDocumentReadyStateToBeInteractiveOrBetter( |
29 time_left_in_seconds) | 29 time_left_in_seconds) |
30 tab.WaitForFrameToBeDisplayed() | 30 tab.WaitForFrameToBeDisplayed() |
OLD | NEW |