| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 from telemetry.page.actions import page_action | 5 from telemetry.page.actions import page_action |
| 6 from telemetry.page.actions.javascript import JavaScriptAction | |
| 7 from telemetry.page.actions.navigate import NavigateAction | 6 from telemetry.page.actions.navigate import NavigateAction |
| 8 from telemetry.page.actions.wait import WaitAction | 7 from telemetry.page.actions.wait import WaitAction |
| 9 from telemetry.web_perf import timeline_interaction_record as tir_module | 8 from telemetry.web_perf import timeline_interaction_record as tir_module |
| 10 | 9 |
| 11 | 10 |
| 12 class ActionRunner(object): | 11 class ActionRunner(object): |
| 13 | 12 |
| 14 def __init__(self, tab): | 13 def __init__(self, tab): |
| 15 self._tab = tab | 14 self._tab = tab |
| 16 | 15 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 'url': target_side_url, | 60 'url': target_side_url, |
| 62 'script_to_evaluate_on_commit': page.script_to_evaluate_on_commit} | 61 'script_to_evaluate_on_commit': page.script_to_evaluate_on_commit} |
| 63 if timeout_seconds: | 62 if timeout_seconds: |
| 64 attributes['timeout_seconds'] = timeout_seconds | 63 attributes['timeout_seconds'] = timeout_seconds |
| 65 self.RunAction(NavigateAction(attributes)) | 64 self.RunAction(NavigateAction(attributes)) |
| 66 | 65 |
| 67 def WaitForNavigate(self, timeout_seconds=60): | 66 def WaitForNavigate(self, timeout_seconds=60): |
| 68 self._tab.WaitForNavigate(timeout_seconds) | 67 self._tab.WaitForNavigate(timeout_seconds) |
| 69 self._tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() | 68 self._tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() |
| 70 | 69 |
| 71 def ExecuteJavaScript(self, js_expression): | 70 def ExecuteJavaScript(self, statement): |
| 72 """Executes a given JavaScript expression. | 71 """Executes a given JavaScript statement. |
| 73 | 72 |
| 74 Example: runner.ExecuteJavaScript('var foo = 1;'); | 73 Example: runner.ExecuteJavaScript('var foo = 1;'); |
| 75 | 74 |
| 76 Args: | 75 Args: |
| 77 js_expression: The expression to execute (provided as string). | 76 statement: The statement to execute (provided as string). |
| 78 """ | 77 """ |
| 79 self.RunAction(JavaScriptAction({'expression': js_expression})) | 78 self._tab.ExecuteJavaScript(statement) |
| 80 | 79 |
| 81 def Wait(self, seconds): | 80 def Wait(self, seconds): |
| 82 """Wait for the number of seconds specified. | 81 """Wait for the number of seconds specified. |
| 83 | 82 |
| 84 Args: | 83 Args: |
| 85 seconds: The number of seconds to wait. | 84 seconds: The number of seconds to wait. |
| 86 """ | 85 """ |
| 87 self.RunAction(WaitAction({'seconds': seconds})) | 86 self.RunAction(WaitAction({'seconds': seconds})) |
| 88 | 87 |
| 89 def WaitForJavaScriptCondition(self, condition, timeout=60): | 88 def WaitForJavaScriptCondition(self, condition, timeout=60): |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 self._action_runner.ExecuteJavaScript('console.time("%s");' % | 151 self._action_runner.ExecuteJavaScript('console.time("%s");' % |
| 153 tir_module.TimelineInteractionRecord.GetJavaScriptMarker( | 152 tir_module.TimelineInteractionRecord.GetJavaScriptMarker( |
| 154 self._label, self._flags)) | 153 self._label, self._flags)) |
| 155 | 154 |
| 156 def End(self): | 155 def End(self): |
| 157 assert self._started | 156 assert self._started |
| 158 self._started = False | 157 self._started = False |
| 159 self._action_runner.ExecuteJavaScript('console.timeEnd("%s");' % | 158 self._action_runner.ExecuteJavaScript('console.timeEnd("%s");' % |
| 160 tir_module.TimelineInteractionRecord.GetJavaScriptMarker( | 159 tir_module.TimelineInteractionRecord.GetJavaScriptMarker( |
| 161 self._label, self._flags)) | 160 self._label, self._flags)) |
| OLD | NEW |