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 from telemetry import page_action | 4 from telemetry.page import page_action |
5 | 5 |
6 class CompoundAction(page_action.PageAction): | 6 class CompoundAction(page_action.PageAction): |
7 def __init__(self, attributes=None): | 7 def __init__(self, attributes=None): |
8 super(CompoundAction, self).__init__(attributes) | 8 super(CompoundAction, self).__init__(attributes) |
9 self._actions = [] | 9 self._actions = [] |
10 from telemetry import all_page_actions | 10 from telemetry.page import all_page_actions |
11 for action_data in self.actions: | 11 for action_data in self.actions: |
12 action = all_page_actions.FindClassWithName( | 12 action = all_page_actions.FindClassWithName( |
13 action_data['action'])(action_data) | 13 action_data['action'])(action_data) |
14 self._actions.append(action) | 14 self._actions.append(action) |
15 | 15 |
16 def CustomizeBrowserOptions(self, options): | 16 def CustomizeBrowserOptions(self, options): |
17 for action in self._actions: | 17 for action in self._actions: |
18 action.CustomizeBrowserOptions(options) | 18 action.CustomizeBrowserOptions(options) |
19 | 19 |
20 def RunsPreviousAction(self): | 20 def RunsPreviousAction(self): |
21 return self._actions and self._actions[0].RunsPreviousAction() | 21 return self._actions and self._actions[0].RunsPreviousAction() |
22 | 22 |
23 def RunAction(self, page, tab, previous_action): | 23 def RunAction(self, page, tab, previous_action): |
24 for i, action in enumerate(self._actions): | 24 for i, action in enumerate(self._actions): |
25 prev_action = self._actions[i - 1] if i > 0 else previous_action | 25 prev_action = self._actions[i - 1] if i > 0 else previous_action |
26 next_action = self._actions[i + 1] if i < len(self._actions) - 1 else None | 26 next_action = self._actions[i + 1] if i < len(self._actions) - 1 else None |
27 | 27 |
28 if (action.RunsPreviousAction() and | 28 if (action.RunsPreviousAction() and |
29 next_action and next_action.RunsPreviousAction()): | 29 next_action and next_action.RunsPreviousAction()): |
30 raise page_action.PageActionFailed('Consecutive actions cannot both ' | 30 raise page_action.PageActionFailed('Consecutive actions cannot both ' |
31 'have RunsPreviousAction() == True.') | 31 'have RunsPreviousAction() == True.') |
32 | 32 |
33 if not (next_action and next_action.RunsPreviousAction()): | 33 if not (next_action and next_action.RunsPreviousAction()): |
34 action.WillRunAction(page, tab) | 34 action.WillRunAction(page, tab) |
35 action.RunAction(page, tab, prev_action) | 35 action.RunAction(page, tab, prev_action) |
OLD | NEW |