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 navigate | 8 from telemetry.page.actions import navigate |
9 from telemetry.page.actions import page_action | 9 from telemetry.page.actions import page_action |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 test_method_name, | 52 test_method_name, |
53 action_name_to_run='', | 53 action_name_to_run='', |
54 needs_browser_restart_after_each_run=False, | 54 needs_browser_restart_after_each_run=False, |
55 discard_first_result=False, | 55 discard_first_result=False, |
56 clear_cache_before_each_run=False): | 56 clear_cache_before_each_run=False): |
57 self.options = None | 57 self.options = None |
58 try: | 58 try: |
59 self._test_method = getattr(self, test_method_name) | 59 self._test_method = getattr(self, test_method_name) |
60 except AttributeError: | 60 except AttributeError: |
61 raise ValueError, 'No such method %s.%s' % ( | 61 raise ValueError, 'No such method %s.%s' % ( |
62 self.__class_, test_method_name) # pylint: disable=E1101 | 62 self.__class_, test_method_name) # pylint: disable=E1101 |
63 self._action_name_to_run = action_name_to_run | 63 self._action_name_to_run = action_name_to_run |
64 self._needs_browser_restart_after_each_run = ( | 64 self._needs_browser_restart_after_each_run = ( |
65 needs_browser_restart_after_each_run) | 65 needs_browser_restart_after_each_run) |
66 self._discard_first_result = discard_first_result | 66 self._discard_first_result = discard_first_result |
67 self._clear_cache_before_each_run = clear_cache_before_each_run | 67 self._clear_cache_before_each_run = clear_cache_before_each_run |
68 self._close_tabs_before_run = True | 68 self._close_tabs_before_run = True |
69 # If the test overrides the TabForPage method, it is considered a multi-tab | 69 # If the test overrides the TabForPage method, it is considered a multi-tab |
70 # test. The main difference between this and a single-tab test is that we | 70 # test. The main difference between this and a single-tab test is that we |
71 # do not attempt recovery for the former if a tab or the browser crashes, | 71 # do not attempt recovery for the former if a tab or the browser crashes, |
72 # because we don't know the current state of tabs (how many are open, etc.) | 72 # because we don't know the current state of tabs (how many are open, etc.) |
73 self.is_multi_tab_test = (self.__class__ is not PageTest and | 73 self.is_multi_tab_test = (self.__class__ is not PageTest and |
74 self.TabForPage.__func__ is not | 74 self.TabForPage.__func__ is not |
75 self.__class__.__bases__[0].TabForPage.__func__) | 75 self.__class__.__bases__[0].TabForPage.__func__) |
| 76 # _exit_requested is set to true when the test requests an early exit. |
| 77 self._exit_requested = False |
76 | 78 |
77 @property | 79 @property |
78 def discard_first_result(self): | 80 def discard_first_result(self): |
79 """When set to True, the first run of the test is discarded. This is | 81 """When set to True, the first run of the test is discarded. This is |
80 useful for cases where it's desirable to have some test resource cached so | 82 useful for cases where it's desirable to have some test resource cached so |
81 the first run of the test can warm things up. """ | 83 the first run of the test can warm things up. """ |
82 return self._discard_first_result | 84 return self._discard_first_result |
83 | 85 |
84 @discard_first_result.setter | 86 @discard_first_result.setter |
85 def discard_first_result(self, discard): | 87 def discard_first_result(self, discard): |
86 self._discard_first_result = discard | 88 self._discard_first_result = discard |
87 | 89 |
88 @property | 90 @property |
89 def clear_cache_before_each_run(self): | 91 def clear_cache_before_each_run(self): |
90 """When set to True, the browser's disk and memory cache will be cleared | 92 """When set to True, the browser's disk and memory cache will be cleared |
91 before each run.""" | 93 before each run.""" |
92 return self._clear_cache_before_each_run | 94 return self._clear_cache_before_each_run |
93 | 95 |
94 @property | 96 @property |
95 def close_tabs_before_run(self): | 97 def close_tabs_before_run(self): |
96 """When set to True, all tabs are closed before running the test for the | 98 """When set to True, all tabs are closed before running the test for the |
97 first time.""" | 99 first time.""" |
98 return self._close_tabs_before_run | 100 return self._close_tabs_before_run |
99 | 101 |
100 @close_tabs_before_run.setter | 102 @close_tabs_before_run.setter |
101 def close_tabs_before_run(self, close_tabs): | 103 def close_tabs_before_run(self, close_tabs): |
102 self._close_tabs_before_run = close_tabs | 104 self._close_tabs_before_run = close_tabs |
103 | 105 |
104 def NeedsBrowserRestartAfterEachRun(self, tab): # pylint: disable=W0613 | 106 def NeedsBrowserRestartAfterEachRun(self, tab): # pylint: disable=W0613 |
105 """Override to specify browser restart after each run.""" | 107 """Override to specify browser restart after each run.""" |
106 return self._needs_browser_restart_after_each_run | 108 return self._needs_browser_restart_after_each_run |
107 | 109 |
108 def AddCommandLineOptions(self, parser): | 110 def AddCommandLineOptions(self, parser): |
109 """Override to expose command-line options for this test. | 111 """Override to expose command-line options for this test. |
110 | 112 |
111 The provided parser is an optparse.OptionParser instance and accepts all | 113 The provided parser is an optparse.OptionParser instance and accepts all |
112 normal results. The parsed options are available in Run as | 114 normal results. The parsed options are available in Run as |
113 self.options.""" | 115 self.options.""" |
114 pass | 116 pass |
(...skipping 10 matching lines...) Expand all Loading... |
125 action.CustomizeBrowserOptions(options) | 127 action.CustomizeBrowserOptions(options) |
126 | 128 |
127 def WillStartBrowser(self, browser): | 129 def WillStartBrowser(self, browser): |
128 """Override to manipulate the browser environment before it launches.""" | 130 """Override to manipulate the browser environment before it launches.""" |
129 pass | 131 pass |
130 | 132 |
131 def DidStartBrowser(self, browser): | 133 def DidStartBrowser(self, browser): |
132 """Override to customize the browser right after it has launched.""" | 134 """Override to customize the browser right after it has launched.""" |
133 pass | 135 pass |
134 | 136 |
135 def CanRunForPage(self, page): #pylint: disable=W0613 | 137 def CanRunForPage(self, page): # pylint: disable=W0613 |
136 """Override to customize if the test can be ran for the given page.""" | 138 """Override to customize if the test can be ran for the given page.""" |
137 return True | 139 return True |
138 | 140 |
139 def WillRunTest(self, tab): | 141 def WillRunTest(self, tab): |
140 """Override to do operations before the page set(s) are navigated.""" | 142 """Override to do operations before the page set(s) are navigated.""" |
141 pass | 143 pass |
142 | 144 |
143 def DidRunTest(self, tab, results): | 145 def DidRunTest(self, tab, results): |
144 """Override to do operations after all page set(s) are completed. | 146 """Override to do operations after all page set(s) are completed. |
145 | 147 |
(...skipping 27 matching lines...) Expand all Loading... |
173 pass | 175 pass |
174 | 176 |
175 def WillRunAction(self, page, tab, action): | 177 def WillRunAction(self, page, tab, action): |
176 """Override to do operations before running the action on the page.""" | 178 """Override to do operations before running the action on the page.""" |
177 pass | 179 pass |
178 | 180 |
179 def DidRunAction(self, page, tab, action): | 181 def DidRunAction(self, page, tab, action): |
180 """Override to do operations after running the action on the page.""" | 182 """Override to do operations after running the action on the page.""" |
181 pass | 183 pass |
182 | 184 |
183 def CreatePageSet(self, args, options): # pylint: disable=W0613 | 185 def CreatePageSet(self, args, options): # pylint: disable=W0613 |
184 """Override to make this test generate its own page set instead of | 186 """Override to make this test generate its own page set instead of |
185 allowing arbitrary page sets entered from the command-line.""" | 187 allowing arbitrary page sets entered from the command-line.""" |
186 return None | 188 return None |
187 | 189 |
188 def CreateExpectations(self, page_set): # pylint: disable=W0613 | 190 def CreateExpectations(self, page_set): # pylint: disable=W0613 |
189 """Override to make this test generate its own expectations instead of | 191 """Override to make this test generate its own expectations instead of |
190 any that may have been defined in the page set.""" | 192 any that may have been defined in the page set.""" |
191 return test_expectations.TestExpectations() | 193 return test_expectations.TestExpectations() |
192 | 194 |
193 def TabForPage(self, page, tab): # pylint: disable=W0613 | 195 def TabForPage(self, page, tab): # pylint: disable=W0613 |
194 """Override to select a different tab for the page. For instance, to | 196 """Override to select a different tab for the page. For instance, to |
195 create a new tab for every page, return tab.browser.tabs.New().""" | 197 create a new tab for every page, return tab.browser.tabs.New().""" |
196 return tab | 198 return tab |
197 | 199 |
198 def ValidatePageSet(self, page_set): | 200 def ValidatePageSet(self, page_set): |
199 """Override to examine the page set before the test run. Useful for | 201 """Override to examine the page set before the test run. Useful for |
200 example to validate that the pageset can be used with the test.""" | 202 example to validate that the pageset can be used with the test.""" |
201 pass | 203 pass |
202 | 204 |
203 def Run(self, options, page, tab, results): | 205 def Run(self, options, page, tab, results): |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 Runs the 'navigate_steps' page attribute as a compound action. | 242 Runs the 'navigate_steps' page attribute as a compound action. |
241 """ | 243 """ |
242 navigate_actions = GetCompoundActionFromPage(page, 'navigate_steps') | 244 navigate_actions = GetCompoundActionFromPage(page, 'navigate_steps') |
243 if not any(isinstance(action, navigate.NavigateAction) | 245 if not any(isinstance(action, navigate.NavigateAction) |
244 for action in navigate_actions): | 246 for action in navigate_actions): |
245 raise page_action.PageActionFailed( | 247 raise page_action.PageActionFailed( |
246 'No NavigateAction in navigate_steps') | 248 'No NavigateAction in navigate_steps') |
247 | 249 |
248 self._RunCompoundAction(page, tab, navigate_actions, False) | 250 self._RunCompoundAction(page, tab, navigate_actions, False) |
249 | 251 |
| 252 def IsExiting(self): |
| 253 return self._exit_requested |
| 254 |
| 255 def RequestExit(self): |
| 256 self._exit_requested = True |
| 257 |
250 @property | 258 @property |
251 def action_name_to_run(self): | 259 def action_name_to_run(self): |
252 return self._action_name_to_run | 260 return self._action_name_to_run |
OLD | NEW |