Chromium Code Reviews| Index: tools/telemetry/telemetry/page/page_test.py |
| diff --git a/tools/telemetry/telemetry/page/page_test.py b/tools/telemetry/telemetry/page/page_test.py |
| index ceb68b68f7843f0c4c4cb71c3ca7ed2bcd84fb76..fb6782c9940ef5d33b2b375b0dca0797b15af927 100644 |
| --- a/tools/telemetry/telemetry/page/page_test.py |
| +++ b/tools/telemetry/telemetry/page/page_test.py |
| @@ -1,50 +1,10 @@ |
| # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| -import logging |
| from telemetry.page import test_expectations |
| -from telemetry.page.actions import all_page_actions |
| from telemetry.page.actions import interact |
| -from telemetry.page.actions import navigate |
| -from telemetry.page.actions import page_action |
| - |
| - |
| -def _GetActionFromData(action_data): |
| - action_name = action_data['action'] |
| - action = all_page_actions.FindClassWithName(action_name) |
| - if not action: |
| - logging.critical('Could not find an action named %s.', action_name) |
| - logging.critical('Check the page set for a typo and check the error ' |
| - 'log for possible Python loading/compilation errors.') |
| - raise Exception('Action "%s" not found.' % action_name) |
| - return action(action_data) |
| - |
| - |
| -def GetSubactionFromData(page, subaction_data, interactive): |
| - subaction_name = subaction_data['action'] |
| - if hasattr(page, subaction_name): |
| - return GetCompoundActionFromPage(page, subaction_name, interactive) |
| - else: |
| - return [_GetActionFromData(subaction_data)] |
| - |
| - |
| -def GetCompoundActionFromPage(page, action_name, interactive=False): |
| - if interactive: |
| - return [interact.InteractAction()] |
| - |
| - if not action_name: |
| - return [] |
| - |
| - action_data_list = getattr(page, action_name) |
| - if not isinstance(action_data_list, list): |
| - action_data_list = [action_data_list] |
| - |
| - action_list = [] |
| - for subaction_data in action_data_list: |
| - for _ in xrange(subaction_data.get('repeat', 1)): |
| - action_list += GetSubactionFromData(page, subaction_data, interactive) |
| - return action_list |
| +from telemetry.page.actions import action_runner |
| class Failure(Exception): |
| @@ -185,13 +145,11 @@ class PageTest(object): |
| this page set. They may, however, be further modified by |
| CustomizeBrowserOptionsForSinglePage or by the profiler. |
| """ |
| - for page in page_set: |
| + for page in page_set.pages: |
| if not self.CanRunForPage(page): |
| return |
| - interactive = options and options.interactive |
| - for action in GetCompoundActionFromPage( |
| - page, self._action_name_to_run, interactive): |
| - action.CustomizeBrowserOptionsForPageSet(options) |
| + #TODO(nednguyen): Remove CustomizeBrowserOptionsForPageSet from actions |
| + page_set.AddCustomizeBrowserOptions(options) |
| def CustomizeBrowserOptionsForSinglePage(self, page, options): |
| """Set options specific to the test and the given page. |
| @@ -200,10 +158,7 @@ class PageTest(object): |
| Changing options at this point only makes sense if the browser is being |
| restarted for each page. |
| """ |
| - interactive = options and options.interactive |
| - for action in GetCompoundActionFromPage( |
| - page, self._action_name_to_run, interactive): |
| - action.CustomizeBrowserOptionsForSinglePage(options) |
| + page.AddCustomizeBrowserOptions(options) |
| def WillStartBrowser(self, browser): |
| """Override to manipulate the browser environment before it launches.""" |
| @@ -291,50 +246,24 @@ class PageTest(object): |
| def Run(self, page, tab, results): |
| interactive = self.options and self.options.interactive |
| - compound_action = GetCompoundActionFromPage( |
| - page, self._action_name_to_run, interactive) |
| + runner = action_runner.ActionRunner(page, tab, self) |
| self.WillRunActions(page, tab) |
| - self._RunCompoundAction(page, tab, compound_action) |
| + if interactive: |
| + runner.RunAction(interact.InteractAction()) |
| + else: |
| + compound_action = getattr(page, self._action_name_to_run) |
|
nduca
2014/03/05 03:00:57
compound_action -> run_method?
|
| + compound_action(runner) |
| self.DidRunActions(page, tab) |
| self._test_method(page, tab, results) |
| - def _RunCompoundAction(self, page, tab, actions, run_setup_methods=True): |
| - for i, action in enumerate(actions): |
| - prev_action = actions[i - 1] if i > 0 else None |
| - next_action = actions[i + 1] if i < len(actions) - 1 else None |
| - |
| - if (action.RunsPreviousAction() and |
| - next_action and next_action.RunsPreviousAction()): |
| - raise page_action.PageActionFailed('Consecutive actions cannot both ' |
| - 'have RunsPreviousAction() == True.') |
| - |
| - if not (next_action and next_action.RunsPreviousAction()): |
| - action.WillRunAction(page, tab) |
| - if run_setup_methods: |
| - self.WillRunAction(page, tab, action) |
| - try: |
| - action.RunAction(page, tab, prev_action) |
| - finally: |
| - if run_setup_methods: |
| - self.DidRunAction(page, tab, action) |
| - |
| - # Note that we must not call util.CloseConnections here. Many tests |
| - # navigate to a URL in the first action and then wait for a condition |
| - # in the second action. Calling util.CloseConnections here often |
| - # aborts resource loads performed by the page. |
| - |
| def RunNavigateSteps(self, page, tab): |
| """Navigates the tab to the page URL attribute. |
| Runs the 'navigate_steps' page attribute as a compound action. |
| """ |
| - navigate_actions = GetCompoundActionFromPage(page, 'navigate_steps') |
| - if not any(isinstance(action, navigate.NavigateAction) |
| - for action in navigate_actions): |
| - raise page_action.PageActionFailed( |
| - 'No NavigateAction in navigate_steps') |
| - |
| - self._RunCompoundAction(page, tab, navigate_actions, False) |
| + if hasattr(page, 'navigate_steps'): |
| + runner = action_runner.ActionRunner(page, tab, None) |
| + page.navigate_steps(runner) |
|
nduca
2014/03/05 03:00:57
method_name -> MethodName
and maybe just call thi
|
| def IsExiting(self): |
| return self._exit_requested |