Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / page / actions / wait_until.py
1 # Copyright 2014 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 class WaitUntil(object):
6
7   def __init__(self, previous_action, attributes=None):
8     assert previous_action is not None, 'wait_until must have a previous action'
9     self.timeout = 60
10     if attributes:
11       for k, v in attributes.iteritems():
12         setattr(self, k, v)
13     self._previous_action = previous_action
14
15   def RunActionAndWait(self, page, tab):
16     if getattr(self, 'condition', None) == 'navigate':
17       self._previous_action.WillRunAction(page, tab)
18       action_to_perform = lambda: self._previous_action.RunAction(page, tab)
19       tab.PerformActionAndWaitForNavigate(action_to_perform, self.timeout)
20       tab.WaitForDocumentReadyStateToBeInteractiveOrBetter()
21
22     elif getattr(self, 'condition', None) == 'href_change':
23       self._previous_action.WillRunAction(page, tab)
24       old_url = tab.EvaluateJavaScript('document.location.href')
25       self._previous_action.RunAction(page, tab)
26       tab.WaitForJavaScriptExpression(
27           'document.location.href != "%s"' % old_url, self.timeout)
28