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
3# found in the LICENSE file.
4
5import time
6
7from telemetry.internal.actions import page_action
8
9
10class NavigateAction(page_action.PageAction):
11  def __init__(self, url, script_to_evaluate_on_commit=None,
12               timeout_in_seconds=60):
13    super(NavigateAction, self).__init__()
14    assert url, 'Must specify url for navigate action'
15    self._url = url
16    self._script_to_evaluate_on_commit = script_to_evaluate_on_commit
17    self._timeout_in_seconds = timeout_in_seconds
18
19  def RunAction(self, tab):
20    start_time = time.time()
21    tab.Navigate(self._url,
22                 self._script_to_evaluate_on_commit,
23                 self._timeout_in_seconds)
24
25    time_left_in_seconds = (start_time + self._timeout_in_seconds
26        - time.time())
27    time_left_in_seconds = max(0, time_left_in_seconds)
28    tab.WaitForDocumentReadyStateToBeInteractiveOrBetter(
29        time_left_in_seconds)
30