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