Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Pyauto powered ui action runner. | 6 """Pyauto powered ui action runner. |
| 7 | 7 |
| 8 Developed primarily to verify validity of the model based action generator. | 8 Developed primarily to verify validity of the model based action generator. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import time | 11 import time |
| 12 import sys | 12 import sys |
| 13 | 13 |
| 14 import pyauto_functional | 14 import pyauto_functional |
| 15 import pyauto | 15 import pyauto |
| 16 import ui_model | 16 import ui_model |
|
Nirnimesh
2012/08/07 00:37:35
Remove this file and ui_model.py
craigdh
2012/08/07 21:08:51
Done.
| |
| 17 | 17 |
| 18 class Runner(pyauto.PyUITest): | 18 class Runner(pyauto.PyUITest): |
| 19 | 19 |
| 20 def setUp(self): | 20 def setUp(self): |
| 21 self.debug_mode = False | 21 self.debug_mode = False |
| 22 pyauto.PyUITest.setUp(self) | 22 pyauto.PyUITest.setUp(self) |
| 23 | 23 |
| 24 def RunActionList(self): | 24 def RunActionList(self): |
| 25 """Runs actions from a file.""" | 25 """Runs actions from a file.""" |
| 26 f = open('list') | 26 f = open('list') |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 if tab_count != expected_count: | 85 if tab_count != expected_count: |
| 86 self.Error('tab count out of sync: count: %d expected: %d' % ( | 86 self.Error('tab count out of sync: count: %d expected: %d' % ( |
| 87 tab_count, expected_count)) | 87 tab_count, expected_count)) |
| 88 window_count = self.GetBrowserWindowCount() | 88 window_count = self.GetBrowserWindowCount() |
| 89 expected_count = self.browser.num_windows | 89 expected_count = self.browser.num_windows |
| 90 if window_count != expected_count: | 90 if window_count != expected_count: |
| 91 self.Error('window count out of sync: count: %d expected %d' % ( | 91 self.Error('window count out of sync: count: %d expected %d' % ( |
| 92 window_count, expected_count)) | 92 window_count, expected_count)) |
| 93 | 93 |
| 94 def _GrabTab(self): | 94 def _GrabTab(self): |
| 95 active_window = self.browser.window_position | |
| 96 window = self.GetBrowserWindow(active_window) | |
| 97 tab_count = self.GetTabCount(self.browser.window_position) | 95 tab_count = self.GetTabCount(self.browser.window_position) |
| 98 active_tab = self.browser.window.tab_position | 96 active_tab = self.browser.window.tab_position |
| 99 if active_tab >= tab_count: | 97 if active_tab >= tab_count: |
| 100 self.Error('active tab out of bounds: count: %d expected active: %d' % ( | 98 self.Error('active tab out of bounds: count: %d expected active: %d' % ( |
| 101 (tab_count, active_tab))) | 99 (tab_count, active_tab))) |
| 102 return window.GetTab(self.browser.window.tab_position) | 100 return {'tab_index': self.browser.window.tab_position, |
| 101 'windex': self.browser.window_position, } | |
| 103 | 102 |
| 104 def _RunInActiveWindow(self, command): | 103 def _RunInActiveWindow(self, command): |
| 105 active_window = self.browser.window_position | 104 active_window = self.browser.window_position |
| 106 self.RunCommand(command, active_window) | 105 self.RunCommand(command, active_window) |
| 107 | 106 |
| 108 def _RunAsyncInActiveWindow(self, command): | 107 def _RunAsyncInActiveWindow(self, command): |
| 109 active_window = self.browser.window_position | 108 active_window = self.browser.window_position |
| 110 self.ApplyAccelerator(command, active_window) | 109 self.ApplyAccelerator(command, active_window) |
| 111 | 110 |
| 112 def _Zoom(self, command): | 111 def _Zoom(self, command): |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 while nav_result != 1: | 179 while nav_result != 1: |
| 181 if retries == 1: | 180 if retries == 1: |
| 182 break | 181 break |
| 183 if retries == 1: | 182 if retries == 1: |
| 184 sys.stdout.write('retry ') | 183 sys.stdout.write('retry ') |
| 185 if retries > 0: | 184 if retries > 0: |
| 186 time.sleep(.1) | 185 time.sleep(.1) |
| 187 sys.stdout.write('%d, ' % retries) | 186 sys.stdout.write('%d, ' % retries) |
| 188 if a == 'navigate': | 187 if a == 'navigate': |
| 189 target = pyauto.GURL(action.split(';')[1]) | 188 target = pyauto.GURL(action.split(';')[1]) |
| 190 nav_result = tab.NavigateToURL(target) | 189 nav_result = self.NavigateToURL(target, **tab) |
| 191 elif a == 'back': | 190 elif a == 'back': |
| 192 self.browser.Back() | 191 self.browser.Back() |
| 193 self.browser.Forward() | 192 self.browser.Forward() |
| 194 nav_result = tab.GoBack() | 193 nav_result = self.TabGoBack(**tab) |
| 195 elif a == 'forward': | 194 elif a == 'forward': |
| 196 self.browser.Forward() | 195 self.browser.Forward() |
| 197 self.browser.Back() | 196 self.browser.Back() |
| 198 nav_result = tab.GoForward() | 197 nav_result = self.TabGoForward(**tab) |
| 199 retries += 1 | 198 retries += 1 |
| 200 if a == 'closetab': | 199 if a == 'closetab': |
| 201 tab = self._GrabTab() | 200 tab = self._GrabTab() |
| 202 ui_model.UpdateState(self.browser, action) | 201 ui_model.UpdateState(self.browser, action) |
| 203 active_window = self.browser.window_position | 202 active_window = self.browser.window_position |
| 204 window_count = self.browser.num_windows | 203 window_count = self.browser.num_windows |
| 205 tab_count = self.browser.window.num_tabs | 204 tab_count = self.browser.window.num_tabs |
| 206 def WindowCount(): | 205 def WindowCount(): |
| 207 actual = self.GetBrowserWindowCount() | 206 actual = self.GetBrowserWindowCount() |
| 208 result = actual == window_count | 207 result = actual == window_count |
| 209 return (result, 'WindowCount (expected %d, actual %d)' % | 208 return (result, 'WindowCount (expected %d, actual %d)' % |
| 210 (window_count, actual)) | 209 (window_count, actual)) |
| 211 def TabCount(): | 210 def TabCount(): |
| 212 actual = self.GetTabCount(active_window) | 211 actual = self.GetTabCount(active_window) |
| 213 result = actual == tab_count | 212 result = actual == tab_count |
| 214 return (result, 'TabCount (expected %d, actual %d)' % | 213 return (result, 'TabCount (expected %d, actual %d)' % |
| 215 (tab_count, actual)) | 214 (tab_count, actual)) |
| 216 tab.Close(True) | 215 self.CloseTab(**tab) |
| 217 self._WaitFor(WindowCount) | 216 self._WaitFor(WindowCount) |
| 218 self._WaitFor(TabCount) | 217 self._WaitFor(TabCount) |
| 219 return False | 218 return False |
| 220 if a == 'closewindow': | 219 if a == 'closewindow': |
| 221 window_count = self.browser.num_windows - 1 | 220 window_count = self.browser.num_windows - 1 |
| 222 def WindowCount(): | 221 def WindowCount(): |
| 223 result = self.GetBrowserWindowCount() == window_count | 222 result = self.GetBrowserWindowCount() == window_count |
| 224 return (result, 'WindowCount (expected %d)' % window_count) | 223 return (result, 'WindowCount (expected %d)' % window_count) |
| 225 self._RunInActiveWindow(pyauto.IDC_CLOSE_WINDOW) | 224 self._RunInActiveWindow(pyauto.IDC_CLOSE_WINDOW) |
| 226 self._WaitFor(WindowCount) | 225 self._WaitFor(WindowCount) |
| 227 if a == 'dragtabout': | 226 if a == 'dragtabout': |
| 228 return False | 227 return False |
| 229 if a == 'dragtableft': | 228 if a == 'dragtableft': |
| 230 self._RunAsyncInActiveWindow(pyauto.IDC_MOVE_TAB_PREVIOUS) | 229 self._RunAsyncInActiveWindow(pyauto.IDC_MOVE_TAB_PREVIOUS) |
| 231 if a == 'dragtabright': | 230 if a == 'dragtabright': |
| 232 self._RunAsyncInActiveWindow(pyauto.IDC_MOVE_TAB_NEXT) | 231 self._RunAsyncInActiveWindow(pyauto.IDC_MOVE_TAB_NEXT) |
| 233 if a == 'lasttab': | 232 if a == 'lasttab': |
| 234 self._RunAsyncInActiveWindow(pyauto.IDC_SELECT_PREVIOUS_TAB) | 233 self._RunAsyncInActiveWindow(pyauto.IDC_SELECT_PREVIOUS_TAB) |
| 235 if a == 'nexttab': | 234 if a == 'nexttab': |
| 236 self._RunAsyncInActiveWindow(pyauto.IDC_SELECT_NEXT_TAB) | 235 self._RunAsyncInActiveWindow(pyauto.IDC_SELECT_NEXT_TAB) |
| 237 if a == 'restoretab': | 236 if a == 'restoretab': |
| 238 active_window = self.browser.window_position | 237 active_window = self.browser.window_position |
| 239 self.ApplyAccelerator(pyauto.IDC_RESTORE_TAB, active_window) | 238 self.ApplyAccelerator(pyauto.IDC_RESTORE_TAB, active_window) |
| 240 self._GrabTab().WaitForTabToBeRestored(self.action_max_timeout_ms()) | 239 self.WaitForTabToBeRestored(**self._GrabTab()) |
| 241 ui_model.UpdateState(self.browser, action) | 240 ui_model.UpdateState(self.browser, action) |
| 242 return False | 241 return False |
| 243 return True | 242 return True |
| 244 | 243 |
| 245 | 244 |
| 246 if __name__ == '__main__': | 245 if __name__ == '__main__': |
| 247 pyauto_functional.Main() | 246 pyauto_functional.Main() |
| OLD | NEW |