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

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

Issue 3226005: Refactory UI to grab shortcut keys, and tests to not look for triggers. (Closed) Base URL: http://git.chromium.org/git/autotest.git
Patch Set: Created 10 years, 3 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 | Annotate | Revision Log
OLDNEW
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 # 2 #
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 7
8 # DESCRIPTION : 8 # DESCRIPTION :
9 # 9 #
10 # Intended for use during manufacturing to validate that all keyboard 10 # Intended for use during manufacturing to validate that all keyboard
(...skipping 14 matching lines...) Expand all
25 from gtk import gdk 25 from gtk import gdk
26 26
27 from autotest_lib.client.bin import factory 27 from autotest_lib.client.bin import factory
28 from autotest_lib.client.bin import factory_ui_lib as ful 28 from autotest_lib.client.bin import factory_ui_lib as ful
29 from autotest_lib.client.bin import test 29 from autotest_lib.client.bin import test
30 from autotest_lib.client.common_lib import error 30 from autotest_lib.client.common_lib import error
31 31
32 32
33 class KeyboardTest: 33 class KeyboardTest:
34 34
35 def __init__(self, kbd_image, bindings, ft_state): 35 def __init__(self, kbd_image, bindings):
36 self._kbd_image = kbd_image 36 self._kbd_image = kbd_image
37 self._bindings = bindings 37 self._bindings = bindings
38 self._ft_state = ft_state
39 self._pressed_keys = set() 38 self._pressed_keys = set()
40 self._deadline = None 39 self._deadline = None
41 self.successful_keys = set() 40 self.successful_keys = set()
42 41
43 def calc_missing_string(self): 42 def calc_missing_string(self):
44 missing_keys = sorted(gdk.keyval_name(k) for k in 43 missing_keys = sorted(gdk.keyval_name(k) for k in
45 set(self._bindings) - self.successful_keys) 44 set(self._bindings) - self.successful_keys)
46 if not missing_keys: 45 if not missing_keys:
47 return '' 46 return ''
48 return 'Missing following keys\n' \ 47 return ('Missing following keys\n' +
49 '沒有偵測到下列按鍵,鍵盤可能故障,請檢修: %s' % ', '.join(missing_keys) 48 '沒有偵測到下列按鍵,鍵盤可能故障,請檢修: %s' %
49 ', '.join(missing_keys))
50 50
51 def timer_event(self, countdown_label): 51 def timer_event(self, countdown_label):
52 if not self._deadline: # Ignore timer with no countdown in progress. 52 if not self._deadline: # Ignore timer with no countdown in progress.
53 return True 53 return True
54 time_remaining = max(0, self._deadline - time.time()) 54 time_remaining = max(0, self._deadline - time.time())
55 if time_remaining == 0: 55 if time_remaining == 0:
56 factory.log('deadline reached') 56 factory.log('deadline reached')
57 gtk.main_quit() 57 gtk.main_quit()
58 countdown_label.set_text('%d' % time_remaining) 58 countdown_label.set_text('%d' % time_remaining)
59 countdown_label.queue_draw() 59 countdown_label.queue_draw()
(...skipping 13 matching lines...) Expand all
73 context.fill() 73 context.fill()
74 for key in self._pressed_keys: 74 for key in self._pressed_keys:
75 coords = self._bindings[key] 75 coords = self._bindings[key]
76 context.rectangle(*coords) 76 context.rectangle(*coords)
77 context.set_source_rgba(*ful.RGBA_YELLOW_OVERLAY) 77 context.set_source_rgba(*ful.RGBA_YELLOW_OVERLAY)
78 context.fill() 78 context.fill()
79 79
80 return True 80 return True
81 81
82 def key_press_event(self, widget, event): 82 def key_press_event(self, widget, event):
83 if self._ft_state.exit_on_trigger(event):
84 return True
85 if ('GDK_MOD1_MASK' in event.state.value_names 83 if ('GDK_MOD1_MASK' in event.state.value_names
86 and event.keyval == gtk.keysyms.q): 84 and event.keyval == gtk.keysyms.q):
87 # Alt-q for early exit. 85 # Alt-q for early exit.
88 gtk.main_quit() 86 gtk.main_quit()
89 return True 87 return True
90 if event.keyval in self.successful_keys: 88 if event.keyval in self.successful_keys:
91 # Ignore keys already found to work successfully. 89 # Ignore keys already found to work successfully.
92 return True 90 return True
93 if event.state != 0: 91 if event.state != 0:
94 factory.log('key (0x%x) ignored because modifier applied (state=%d)' 92 factory.log('key (0x%x) ignored because modifier applied (state=%d)'
(...skipping 28 matching lines...) Expand all
123 def register_callbacks(self, window): 121 def register_callbacks(self, window):
124 window.connect('key-press-event', self.key_press_event) 122 window.connect('key-press-event', self.key_press_event)
125 window.connect('key-release-event', self.key_release_event) 123 window.connect('key-release-event', self.key_release_event)
126 window.add_events(gdk.KEY_PRESS_MASK | gdk.KEY_RELEASE_MASK) 124 window.add_events(gdk.KEY_PRESS_MASK | gdk.KEY_RELEASE_MASK)
127 125
128 126
129 class factory_Keyboard(test.test): 127 class factory_Keyboard(test.test):
130 version = 1 128 version = 1
131 preserve_srcdir = True 129 preserve_srcdir = True
132 130
133 def run_once(self, 131 def run_once(self, layout=None):
134 test_widget_size=None,
135 trigger_set=None,
136 layout=None):
137 132
138 factory.log('%s run_once' % self.__class__) 133 factory.log('%s run_once' % self.__class__)
139 134
140 ft_state = ful.State(trigger_set)
141
142 os.chdir(self.srcdir) 135 os.chdir(self.srcdir)
143 kbd_image = cairo.ImageSurface.create_from_png('%s.png' % layout) 136 kbd_image = cairo.ImageSurface.create_from_png('%s.png' % layout)
144 image_size = (kbd_image.get_width(), kbd_image.get_height()) 137 image_size = (kbd_image.get_width(), kbd_image.get_height())
145 138
146 with open('%s.bindings' % layout, 'r') as file: 139 with open('%s.bindings' % layout, 'r') as file:
147 bindings = eval(file.read()) 140 bindings = eval(file.read())
148 141
149 test = KeyboardTest(kbd_image, bindings, ft_state) 142 test = KeyboardTest(kbd_image, bindings)
150 143
151 drawing_area = gtk.DrawingArea() 144 drawing_area = gtk.DrawingArea()
152 drawing_area.set_size_request(*image_size) 145 drawing_area.set_size_request(*image_size)
153 drawing_area.connect('expose_event', test.expose_event) 146 drawing_area.connect('expose_event', test.expose_event)
154 drawing_area.add_events(gdk.EXPOSURE_MASK) 147 drawing_area.add_events(gdk.EXPOSURE_MASK)
155 148
156 countdown_widget, countdown_label = ful.make_countdown_widget() 149 countdown_widget, countdown_label = ful.make_countdown_widget()
157 gobject.timeout_add(1000, test.timer_event, countdown_label) 150 gobject.timeout_add(1000, test.timer_event, countdown_label)
158 151
159 test_widget = gtk.VBox() 152 test_widget = gtk.VBox()
160 test_widget.set_spacing(20) 153 test_widget.set_spacing(20)
161 test_widget.pack_start(drawing_area, False, False) 154 test_widget.pack_start(drawing_area, False, False)
162 test_widget.pack_start(countdown_widget, False, False) 155 test_widget.pack_start(countdown_widget, False, False)
163 156
164 ft_state.run_test_widget( 157 ful.run_test_widget(self.job, test_widget,
165 test_widget=test_widget,
166 test_widget_size=test_widget_size,
167 window_registration_callback=test.register_callbacks) 158 window_registration_callback=test.register_callbacks)
168 159
169 missing = test.calc_missing_string() 160 missing = test.calc_missing_string()
170 if missing: 161 if missing:
171 raise error.TestFail(missing) 162 raise error.TestFail(missing)
172 163
173 factory.log('%s run_once finished' % self.__class__) 164 factory.log('%s run_once finished' % self.__class__)
OLDNEW
« no previous file with comments | « client/site_tests/factory_ExternalStorage/factory_ExternalStorage.py ('k') | client/site_tests/factory_Leds/factory_Leds.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698