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..b8e53320e34292fd30a3686c603ffde99fc01685 100644 |
--- a/tools/telemetry/telemetry/page/page_test.py |
+++ b/tools/telemetry/telemetry/page/page_test.py |
@@ -1,13 +1,13 @@ |
# 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 action_runner as action_runner_module |
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): |
@@ -47,6 +47,13 @@ def GetCompoundActionFromPage(page, action_name, interactive=False): |
return action_list |
+def GetRunMethodForPage(page, action_name): |
+ def RunMethod(action_runner): |
+ for action in GetCompoundActionFromPage(page, action_name): |
+ action_runner.RunAction(action) |
+ return RunMethod |
+ |
+ |
class Failure(Exception): |
"""Exception that can be thrown from PageMeasurement to indicate an |
undesired but designed-for problem.""" |
@@ -185,13 +192,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 +205,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 +293,31 @@ 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) |
+ action_runner = action_runner_module.ActionRunner(page, tab, self) |
self.WillRunActions(page, tab) |
- self._RunCompoundAction(page, tab, compound_action) |
+ if interactive: |
+ action_runner.RunAction(interact.InteractAction()) |
+ else: |
+ run_method = getattr(page, self._action_name_to_run) |
+ # method is runnable, this must be from the legacy json page_set |
+ if not callable(run_method): |
+ run_method = GetRunMethodForPage(page, self._action_name_to_run) |
+ run_method(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, 'RunNavigateSteps'): |
+ action_runner = action_runner_module.ActionRunner(page, tab, None) |
+ page.RunNavigateSteps(action_runner) |
+ elif hasattr(page, 'navigate_steps'): |
+ action_runner = action_runner_module.ActionRunner(page, tab, None) |
+ run_method = GetRunMethodForPage(page, 'navigate_steps') |
+ run_method(action_runner) |
def IsExiting(self): |
return self._exit_requested |