13551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)# Copyright 2013 The Chromium Authors. All rights reserved.
23551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be
33551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)# found in the LICENSE file.
43551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)from telemetry.page.actions import page_action
53551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
6cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
73551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class NavigateAction(page_action.PageAction):
83551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  def __init__(self, attributes=None):
93551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    super(NavigateAction, self).__init__(attributes)
10cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    assert hasattr(self, 'url'), 'Must specify url for navigate action'
113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
12cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  def RunAction(self, tab):
13cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    script_to_evaluate_on_commit = None
14cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    if hasattr(self, 'script_to_evaluate_on_commit'):
15cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      script_to_evaluate_on_commit = getattr(self,
16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                             'script_to_evaluate_on_commit')
1723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)    if hasattr(self, 'timeout_seconds') and self.timeout_seconds:
18cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      tab.Navigate(self.url,
19cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                   script_to_evaluate_on_commit,
2023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)                   self.timeout_seconds)
2123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)    else:
22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      tab.Navigate(self.url, script_to_evaluate_on_commit)
234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    tab.WaitForDocumentReadyStateToBeInteractiveOrBetter()
24