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.
5 class WaitUntil(object):
7 def __init__(self, previous_action, attributes=None):
8 assert previous_action is not None, 'wait_until must have a previous action'
11 for k, v in attributes.iteritems():
13 self._previous_action = previous_action
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()
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)