Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: client/site_tests/factory_Touchpad/factory_Touchpad.py

Issue 2836043: Relocate library files for wider access and re-use; also associated cleanup. (Closed) Base URL: ssh://gitrw.chromium.org/autotest.git
Patch Set: patch typo Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2010 The Chromium OS 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 4
5 5
6 from autotest_lib.client.bin import test
7 from autotest_lib.client.common_lib import error
8 from autotest_lib.client.common_lib import factory_test
9
10 import cairo 6 import cairo
11 import gobject 7 import gobject
12 import gtk 8 import gtk
13 import pango 9 import pango
14 import time 10 import time
15 import os 11 import os
16 import sys 12 import sys
17 import subprocess 13 import subprocess
18 14
15 from autotest_lib.client.bin import factory
16 from autotest_lib.client.bin import factory_ui_lib as ful
17 from autotest_lib.client.bin import test
18 from autotest_lib.client.common_lib import error
19
19 20
20 _SYNCLIENT_SETTINGS_CMDLINE = '/usr/bin/synclient -l' 21 _SYNCLIENT_SETTINGS_CMDLINE = '/usr/bin/synclient -l'
21 _SYNCLIENT_CMDLINE = '/usr/bin/synclient -m 50' 22 _SYNCLIENT_CMDLINE = '/usr/bin/synclient -m 50'
22 23
23 _RGBA_GREEN_OVERLAY = (0, 0.5, 0, 0.6) 24 _RGBA_GREEN_OVERLAY = (0, 0.5, 0, 0.6)
24 25
25 _X_SEGMENTS = 5 26 _X_SEGMENTS = 5
26 _Y_SEGMENTS = 4 27 _Y_SEGMENTS = 4
27 28
28 _X_TP_OFFSET = 10 29 _X_TP_OFFSET = 10
29 _Y_TP_OFFSET = 10 30 _Y_TP_OFFSET = 10
30 _TP_WIDTH = 397 31 _TP_WIDTH = 397
31 _TP_HEIGHT = 213 32 _TP_HEIGHT = 213
32 _TP_SECTOR_WIDTH = (_TP_WIDTH / _X_SEGMENTS) - 1 33 _TP_SECTOR_WIDTH = (_TP_WIDTH / _X_SEGMENTS) - 1
33 _TP_SECTOR_HEIGHT = (_TP_HEIGHT / _Y_SEGMENTS) - 1 34 _TP_SECTOR_HEIGHT = (_TP_HEIGHT / _Y_SEGMENTS) - 1
34 35
35 _X_SP_OFFSET = 432 36 _X_SP_OFFSET = 432
36 _SP_WIDTH = 19 37 _SP_WIDTH = 19
37 38
38 39
39 class TouchpadTest: 40 class TouchpadTest:
40 41
41 def __init__(self, tp_image, drawing_area): 42 def __init__(self, tp_image, drawing_area, ft_state):
42 self._tp_image = tp_image 43 self._tp_image = tp_image
43 self._drawing_area = drawing_area 44 self._drawing_area = drawing_area
45 self._ft_state = ft_state
44 self._motion_grid = {} 46 self._motion_grid = {}
45 for x in range(_X_SEGMENTS): 47 for x in range(_X_SEGMENTS):
46 for y in range(_Y_SEGMENTS): 48 for y in range(_Y_SEGMENTS):
47 self._motion_grid['%d,%d' % (x, y)] = False 49 self._motion_grid['%d,%d' % (x, y)] = False
48 self._scroll_array = {} 50 self._scroll_array = {}
49 for y in range(_Y_SEGMENTS): 51 for y in range(_Y_SEGMENTS):
50 self._scroll_array[y] = False 52 self._scroll_array[y] = False
51 self._l_click = False 53 self._l_click = False
52 self._r_click = False 54 self._r_click = False
53 55
54 def timer_event(self, window): 56 def timer_event(self, window):
55 if not self._deadline: 57 if not self._deadline:
56 # Ignore timer events with no countdown in progress. 58 # Ignore timer events with no countdown in progress.
57 return True 59 return True
58 if self._deadline <= time.time(): 60 if self._deadline <= time.time():
59 XXX_log('deadline reached') 61 XXX_log('deadline reached')
60 gtk.main_quit() 62 gtk.main_quit()
61 window.queue_draw() 63 window.queue_draw()
62 return True 64 return True
63 65
64 def device_event(self, x, y, z, fingers, left, right): 66 def device_event(self, x, y, z, fingers, left, right):
65 x_seg = int(round(x / (1.0 / float(_X_SEGMENTS - 1)))) 67 x_seg = int(round(x / (1.0 / float(_X_SEGMENTS - 1))))
66 y_seg = int(round(y / (1.0 / float(_Y_SEGMENTS - 1)))) 68 y_seg = int(round(y / (1.0 / float(_Y_SEGMENTS - 1))))
67 index = '%d,%d' % (x_seg, y_seg) 69 index = '%d,%d' % (x_seg, y_seg)
68 assert(index in self._motion_grid) 70 assert(index in self._motion_grid)
69 assert(y_seg in self._scroll_array) 71 assert(y_seg in self._scroll_array)
70 if left and not self._l_click: 72 if left and not self._l_click:
71 self._l_click = True 73 self._l_click = True
72 factory_test.XXX_log('ok left click') 74 factory.log('ok left click')
73 elif right and not self._r_click: 75 elif right and not self._r_click:
74 self._r_click = True 76 self._r_click = True
75 factory_test.XXX_log('ok right click') 77 factory.log('ok right click')
76 elif fingers == 1 and not self._motion_grid[index]: 78 elif fingers == 1 and not self._motion_grid[index]:
77 self._motion_grid[index] = True 79 self._motion_grid[index] = True
78 elif fingers == 2 and not self._scroll_array[y_seg]: 80 elif fingers == 2 and not self._scroll_array[y_seg]:
79 self._scroll_array[y_seg] = True 81 self._scroll_array[y_seg] = True
80 else: 82 else:
81 return 83 return
82 self._drawing_area.queue_draw() 84 self._drawing_area.queue_draw()
83 missing_motion_sectors = set(i for i, v in self._motion_grid.items() 85 missing_motion_sectors = set(i for i, v in self._motion_grid.items()
84 if v is False) 86 if v is False)
85 missing_scroll_segments = set(i for i, v in self._scroll_array.items() 87 missing_scroll_segments = set(i for i, v in self._scroll_array.items()
(...skipping 25 matching lines...) Expand all
111 continue 113 continue
112 y = _Y_TP_OFFSET + (y_seg * (_TP_SECTOR_HEIGHT + 1)) 114 y = _Y_TP_OFFSET + (y_seg * (_TP_SECTOR_HEIGHT + 1))
113 coords = (_X_SP_OFFSET, y, _SP_WIDTH, _TP_SECTOR_HEIGHT) 115 coords = (_X_SP_OFFSET, y, _SP_WIDTH, _TP_SECTOR_HEIGHT)
114 context.rectangle(*coords) 116 context.rectangle(*coords)
115 context.set_source_rgba(*_RGBA_GREEN_OVERLAY) 117 context.set_source_rgba(*_RGBA_GREEN_OVERLAY)
116 context.fill() 118 context.fill()
117 119
118 return True 120 return True
119 121
120 def key_press_event(self, widget, event): 122 def key_press_event(self, widget, event):
121 factory_test.test_switch_on_trigger(event) 123 self._ft_state.exit_on_trigger(event)
122 return True 124 return True
123 125
124 def button_press_event(self, widget, event): 126 def button_press_event(self, widget, event):
125 factory_test.XXX_log('button_press_event %d,%d' % (event.x, event.y)) 127 factory.log('button_press_event %d,%d' % (event.x, event.y))
126 return True 128 return True
127 129
128 def button_release_event(self, widget, event): 130 def button_release_event(self, widget, event):
129 factory_test.XXX_log('button_release_event %d,%d' % (event.x, event.y)) 131 factory.log('button_release_event %d,%d' % (event.x, event.y))
130 return True 132 return True
131 133
132 def motion_event(self, widget, event): 134 def motion_event(self, widget, event):
133 factory_test.XXX_log('motion_event %d,%d' % (event.x, event.y)) 135 factory.log('motion_event %d,%d' % (event.x, event.y))
134 return True 136 return True
135 137
136 def register_callbacks(self, window): 138 def register_callbacks(self, window):
137 window.connect('key-press-event', self.key_press_event) 139 window.connect('key-press-event', self.key_press_event)
138 window.add_events(gtk.gdk.KEY_PRESS_MASK) 140 window.add_events(gtk.gdk.KEY_PRESS_MASK)
139 141
140 142
141 class SynClient: 143 class SynClient:
142 144
143 def __init__(self, test): 145 def __init__(self, test):
(...skipping 11 matching lines...) Expand all
155 self._xmax = float(settings['RightEdge']) 157 self._xmax = float(settings['RightEdge'])
156 self._ymin = float(settings['TopEdge']) 158 self._ymin = float(settings['TopEdge'])
157 self._ymax = float(settings['BottomEdge']) 159 self._ymax = float(settings['BottomEdge'])
158 self._proc = subprocess.Popen(_SYNCLIENT_CMDLINE.split(), 160 self._proc = subprocess.Popen(_SYNCLIENT_CMDLINE.split(),
159 stdout=subprocess.PIPE) 161 stdout=subprocess.PIPE)
160 gobject.io_add_watch(self._proc.stdout, gobject.IO_IN, self.recv) 162 gobject.io_add_watch(self._proc.stdout, gobject.IO_IN, self.recv)
161 163
162 def recv(self, src, cond): 164 def recv(self, src, cond):
163 data = self._proc.stdout.readline().split() 165 data = self._proc.stdout.readline().split()
164 if len(data) != 17: 166 if len(data) != 17:
165 factory_test.XXX_log('unknown data : %d, %s' % (len(data), data)) 167 factory.log('unknown data : %d, %s' % (len(data), data))
166 return True 168 return True
167 if data[0] == 'time': 169 if data[0] == 'time':
168 return True 170 return True
169 data_x, data_y, z, f, w, l, r = data[1:8] 171 data_x, data_y, z, f, w, l, r = data[1:8]
170 x = sorted([self._xmin, float(data_x), self._xmax])[1] 172 x = sorted([self._xmin, float(data_x), self._xmax])[1]
171 x = (x - self._xmin) / (self._xmax - self._xmin) 173 x = (x - self._xmin) / (self._xmax - self._xmin)
172 y = sorted([self._ymin, float(data_y), self._ymax])[1] 174 y = sorted([self._ymin, float(data_y), self._ymax])[1]
173 y = (y - self._ymin) / (self._ymax - self._ymin) 175 y = (y - self._ymin) / (self._ymax - self._ymin)
174 self._test.device_event(x, y, int(z), int(f), int(l), int(r)) 176 self._test.device_event(x, y, int(z), int(f), int(l), int(r))
175 return True 177 return True
176 178
177 def quit(self): 179 def quit(self):
178 factory_test.XXX_log('killing SynClient ...') 180 factory.log('killing SynClient ...')
179 self._proc.kill() 181 self._proc.kill()
180 factory_test.XXX_log('dead') 182 factory.log('dead')
181 183
182 184
183 class factory_Touchpad(test.test): 185 class factory_Touchpad(test.test):
184 version = 1 186 version = 1
185 preserve_srcdir = True 187 preserve_srcdir = True
186 188
187 def run_once(self, test_widget_size=None, trigger_set=None, 189 def run_once(self,
190 test_widget_size=None,
191 trigger_set=None,
188 result_file_path=None): 192 result_file_path=None):
189 193
190 factory_test.XXX_log('factory_Touchpad') 194 factory.log('%s run_once' % self.__class__)
191 195
192 factory_test.init(trigger_set=trigger_set, 196 ft_state = ful.State(
193 result_file_path=result_file_path) 197 trigger_set=trigger_set,
198 result_file_path=result_file_path)
194 199
195 os.chdir(self.srcdir) 200 os.chdir(self.srcdir)
196 tp_image = cairo.ImageSurface.create_from_png('touchpad.png') 201 tp_image = cairo.ImageSurface.create_from_png('touchpad.png')
197 image_size = (tp_image.get_width(), tp_image.get_height()) 202 image_size = (tp_image.get_width(), tp_image.get_height())
198 203
199 drawing_area = gtk.DrawingArea() 204 drawing_area = gtk.DrawingArea()
200 205
201 test = TouchpadTest(tp_image, drawing_area) 206 test = TouchpadTest(tp_image, drawing_area, ft_state)
202 207
203 drawing_area.set_size_request(*image_size) 208 drawing_area.set_size_request(*image_size)
204 drawing_area.connect('expose_event', test.expose_event) 209 drawing_area.connect('expose_event', test.expose_event)
205 drawing_area.connect('button-press-event', test.button_press_event) 210 drawing_area.connect('button-press-event', test.button_press_event)
206 drawing_area.connect('button-release-event', test.button_release_event) 211 drawing_area.connect('button-release-event', test.button_release_event)
207 drawing_area.connect('motion-notify-event', test.motion_event) 212 drawing_area.connect('motion-notify-event', test.motion_event)
208 drawing_area.add_events(gtk.gdk.EXPOSURE_MASK | 213 drawing_area.add_events(gtk.gdk.EXPOSURE_MASK |
209 gtk.gdk.BUTTON_PRESS_MASK | 214 gtk.gdk.BUTTON_PRESS_MASK |
210 gtk.gdk.BUTTON_RELEASE_MASK | 215 gtk.gdk.BUTTON_RELEASE_MASK |
211 gtk.gdk.POINTER_MOTION_MASK) 216 gtk.gdk.POINTER_MOTION_MASK)
212 217
213 synclient = SynClient(test) 218 synclient = SynClient(test)
214 219
215 factory_test.run_test_widget( 220 ft_state.run_test_widget(
216 test_widget=drawing_area, 221 test_widget=drawing_area,
217 test_widget_size=test_widget_size, 222 test_widget_size=test_widget_size,
218 window_registration_callback=test.register_callbacks, 223 window_registration_callback=test.register_callbacks,
219 cleanup_callback=synclient.quit) 224 cleanup_callback=synclient.quit)
220 225
221 factory_test.XXX_log('exiting factory_Touchpad') 226 factory.log('%s run_once finished' % self.__class__)
OLDNEW
« no previous file with comments | « client/site_tests/factory_ScriptWrapper/factory_ScriptWrapper.py ('k') | client/site_tests/suite_Factory/control » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698