| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 re | 5 import re |
| 6 import time | 6 import time |
| 7 | 7 |
| 8 from telemetry.core import util | 8 from telemetry.core import util |
| 9 from telemetry.page.actions import page_action | 9 from telemetry.page.actions import page_action |
| 10 | 10 |
| 11 class WaitAction(page_action.PageAction): | 11 class WaitAction(page_action.PageAction): |
| 12 def __init__(self, attributes=None): | 12 def __init__(self, attributes=None): |
| 13 self.timeout = 60 | 13 self.timeout = 60 |
| 14 super(WaitAction, self).__init__(attributes) | 14 super(WaitAction, self).__init__(attributes) |
| 15 | 15 |
| 16 def RunsPreviousAction(self): | 16 def RunsPreviousAction(self): |
| 17 return (getattr(self, 'condition', None) == 'navigate' or | 17 return (getattr(self, 'condition', None) == 'navigate' or |
| 18 getattr(self, 'condition', None) == 'href_change') | 18 getattr(self, 'condition', None) == 'href_change') |
| 19 | 19 |
| 20 def RunAction(self, page, tab, previous_action): | 20 def RunAction(self, page, tab, previous_action): |
| 21 tab.ExecuteJavaScript( | 21 tab.ExecuteJavaScript( |
| 22 'console.time("' + self.GetTimelineMarkerLabel() + '")') | 22 'console.time("' + self.GetTimelineMarkerName() + '")') |
| 23 | 23 |
| 24 if hasattr(self, 'seconds'): | 24 if hasattr(self, 'seconds'): |
| 25 time.sleep(self.seconds) | 25 time.sleep(self.seconds) |
| 26 | 26 |
| 27 elif getattr(self, 'condition', None) == 'navigate': | 27 elif getattr(self, 'condition', None) == 'navigate': |
| 28 if not previous_action: | 28 if not previous_action: |
| 29 raise page_action.PageActionFailed('You need to perform an action ' | 29 raise page_action.PageActionFailed('You need to perform an action ' |
| 30 'before waiting for navigate.') | 30 'before waiting for navigate.') |
| 31 previous_action.WillRunAction(page, tab) | 31 previous_action.WillRunAction(page, tab) |
| 32 action_to_perform = lambda: previous_action.RunAction(page, tab, None) | 32 action_to_perform = lambda: previous_action.RunAction(page, tab, None) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 62 tab.WaitForJavaScriptExpression('%s != null' % code, self.timeout) | 62 tab.WaitForJavaScriptExpression('%s != null' % code, self.timeout) |
| 63 else: | 63 else: |
| 64 raise page_action.PageActionFailed( | 64 raise page_action.PageActionFailed( |
| 65 'No element condition given to wait') | 65 'No element condition given to wait') |
| 66 elif hasattr(self, 'javascript'): | 66 elif hasattr(self, 'javascript'): |
| 67 tab.WaitForJavaScriptExpression(self.javascript, self.timeout) | 67 tab.WaitForJavaScriptExpression(self.javascript, self.timeout) |
| 68 else: | 68 else: |
| 69 raise page_action.PageActionFailed('No wait condition found') | 69 raise page_action.PageActionFailed('No wait condition found') |
| 70 | 70 |
| 71 tab.ExecuteJavaScript( | 71 tab.ExecuteJavaScript( |
| 72 'console.timeEnd("' + self.GetTimelineMarkerLabel() + '")') | 72 'console.timeEnd("' + self.GetTimelineMarkerName() + '")') |
| 73 | 73 |
| 74 def GetTimelineMarkerLabel(self): | 74 def GetTimelineMarkerName(self): |
| 75 return 'WaitAction::RunAction' | 75 return 'WaitAction::RunAction' |
| OLD | NEW |