| 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 import logging | 4 import logging |
| 5 | 5 |
| 6 from telemetry.page import test_expectations | 6 from telemetry.page import test_expectations |
| 7 from telemetry.page.actions import all_page_actions | 7 from telemetry.page.actions import all_page_actions |
| 8 from telemetry.page.actions import interact | 8 from telemetry.page.actions import interact |
| 9 from telemetry.page.actions import navigate | 9 from telemetry.page.actions import navigate |
| 10 from telemetry.page.actions import page_action | 10 from telemetry.page.actions import page_action |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 pass | 188 pass |
| 189 | 189 |
| 190 def DidStartBrowser(self, browser): | 190 def DidStartBrowser(self, browser): |
| 191 """Override to customize the browser right after it has launched.""" | 191 """Override to customize the browser right after it has launched.""" |
| 192 pass | 192 pass |
| 193 | 193 |
| 194 def CanRunForPage(self, page): # pylint: disable=W0613 | 194 def CanRunForPage(self, page): # pylint: disable=W0613 |
| 195 """Override to customize if the test can be ran for the given page.""" | 195 """Override to customize if the test can be ran for the given page.""" |
| 196 return True | 196 return True |
| 197 | 197 |
| 198 def WillRunTest(self): | 198 def WillRunTest(self, options): |
| 199 """Override to do operations before the page set(s) are navigated.""" | 199 """Override to do operations before the page set(s) are navigated.""" |
| 200 pass | 200 self.options = options |
| 201 | 201 |
| 202 def DidRunTest(self, browser, results): | 202 def DidRunTest(self, browser, results): # pylint: disable=W0613 |
| 203 """Override to do operations after all page set(s) are completed. | 203 """Override to do operations after all page set(s) are completed. |
| 204 | 204 |
| 205 This will occur before the browser is torn down. | 205 This will occur before the browser is torn down. |
| 206 """ | 206 """ |
| 207 pass | 207 self.options = None |
| 208 | 208 |
| 209 def WillRunPageRepeats(self, page): | 209 def WillRunPageRepeats(self, page): |
| 210 """Override to do operations before each page is iterated over.""" | 210 """Override to do operations before each page is iterated over.""" |
| 211 pass | 211 pass |
| 212 | 212 |
| 213 def DidRunPageRepeats(self, page): | 213 def DidRunPageRepeats(self, page): |
| 214 """Override to do operations after each page is iterated over.""" | 214 """Override to do operations after each page is iterated over.""" |
| 215 pass | 215 pass |
| 216 | 216 |
| 217 def DidStartHTTPServer(self, tab): | 217 def DidStartHTTPServer(self, tab): |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 def TabForPage(self, page, browser): # pylint: disable=W0613 | 260 def TabForPage(self, page, browser): # pylint: disable=W0613 |
| 261 """Override to select a different tab for the page. For instance, to | 261 """Override to select a different tab for the page. For instance, to |
| 262 create a new tab for every page, return browser.tabs.New().""" | 262 create a new tab for every page, return browser.tabs.New().""" |
| 263 return browser.tabs[0] | 263 return browser.tabs[0] |
| 264 | 264 |
| 265 def ValidatePageSet(self, page_set): | 265 def ValidatePageSet(self, page_set): |
| 266 """Override to examine the page set before the test run. Useful for | 266 """Override to examine the page set before the test run. Useful for |
| 267 example to validate that the pageset can be used with the test.""" | 267 example to validate that the pageset can be used with the test.""" |
| 268 pass | 268 pass |
| 269 | 269 |
| 270 def Run(self, options, page, tab, results): | 270 def Run(self, page, tab, results): |
| 271 self.options = options | 271 interactive = self.options and self.options.interactive |
| 272 interactive = options and options.interactive | |
| 273 compound_action = GetCompoundActionFromPage( | 272 compound_action = GetCompoundActionFromPage( |
| 274 page, self._action_name_to_run, interactive) | 273 page, self._action_name_to_run, interactive) |
| 275 self.WillRunActions(page, tab) | 274 self.WillRunActions(page, tab) |
| 276 self._RunCompoundAction(page, tab, compound_action) | 275 self._RunCompoundAction(page, tab, compound_action) |
| 277 self.DidRunActions(page, tab) | 276 self.DidRunActions(page, tab) |
| 278 try: | 277 self._test_method(page, tab, results) |
| 279 self._test_method(page, tab, results) | |
| 280 finally: | |
| 281 self.options = None | |
| 282 | 278 |
| 283 def _RunCompoundAction(self, page, tab, actions, run_setup_methods=True): | 279 def _RunCompoundAction(self, page, tab, actions, run_setup_methods=True): |
| 284 for i, action in enumerate(actions): | 280 for i, action in enumerate(actions): |
| 285 prev_action = actions[i - 1] if i > 0 else None | 281 prev_action = actions[i - 1] if i > 0 else None |
| 286 next_action = actions[i + 1] if i < len(actions) - 1 else None | 282 next_action = actions[i + 1] if i < len(actions) - 1 else None |
| 287 | 283 |
| 288 if (action.RunsPreviousAction() and | 284 if (action.RunsPreviousAction() and |
| 289 next_action and next_action.RunsPreviousAction()): | 285 next_action and next_action.RunsPreviousAction()): |
| 290 raise page_action.PageActionFailed('Consecutive actions cannot both ' | 286 raise page_action.PageActionFailed('Consecutive actions cannot both ' |
| 291 'have RunsPreviousAction() == True.') | 287 'have RunsPreviousAction() == True.') |
| (...skipping 28 matching lines...) Expand all Loading... |
| 320 | 316 |
| 321 def IsExiting(self): | 317 def IsExiting(self): |
| 322 return self._exit_requested | 318 return self._exit_requested |
| 323 | 319 |
| 324 def RequestExit(self): | 320 def RequestExit(self): |
| 325 self._exit_requested = True | 321 self._exit_requested = True |
| 326 | 322 |
| 327 @property | 323 @property |
| 328 def action_name_to_run(self): | 324 def action_name_to_run(self): |
| 329 return self._action_name_to_run | 325 return self._action_name_to_run |
| OLD | NEW |