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

Side by Side Diff: client/common_lib/factory_test.py

Issue 2857012: Batched update of factory tests. (Closed) Base URL: ssh://gitrw.chromium.org/autotest.git
Patch Set: finished comment Created 10 years, 6 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
« no previous file with comments | « no previous file | client/deps/factory/startx.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 # DESCRIPTION : 6 # DESCRIPTION :
7 # 7 #
8 # This library provides convenience routines to launch factory tests. 8 # This library provides convenience routines to launch factory tests.
9 # This includes support for identifying keyboard test switching 9 # This includes support for identifying keyboard test switching
10 # triggers, grabbing control of the keyboard and mouse, and making the 10 # triggers, grabbing control of the keyboard and mouse, and making the
11 # mouse cursor disappear. It also manages communication of any found 11 # mouse cursor disappear. It also manages communication of any found
12 # keyboard triggers to the control process, via writing data to 12 # keyboard triggers to the control process, via writing data to
13 # _result_file_path. 13 # _result_file_path.
14 14
15 15
16 from autotest_lib.client.common_lib import error 16 from autotest_lib.client.common_lib import error
17 17
18 import gtk 18 import gtk
19 import sys 19 import sys
20 20
21 21
22 def XXX_log(s): 22 def XXX_log(s):
23 print >> sys.stderr, '--- XXX : ' + s 23 print >> sys.stderr, 'FACTORY: ' + s
24 24
25 25
26 _BLACK = gtk.gdk.color_parse('black') 26 _BLACK = gtk.gdk.color_parse('black')
27 27
28 28
29 _got_trigger = None 29 _got_trigger = None
30 _trigger_set = None 30 _trigger_set = None
31 _result_file_path = None 31 _result_file_path = None
32 32
33 33
34 def init(trigger_set=set(), result_file_path=None): 34 def init(trigger_set=set(), result_file_path=None):
35 global _trigger_set, _result_file_path 35 global _trigger_set, _result_file_path
36 _result_file_path = result_file_path 36 _result_file_path = result_file_path
37 _trigger_set = [ord(x) for x in trigger_set] 37 _trigger_set = [ord(x) for x in trigger_set]
38 38
39 39
40 def test_switch_on_trigger(event): 40 def test_switch_on_trigger(event):
41 char = event.keyval in range(32,127) and chr(event.keyval) or None 41 char = event.keyval in range(32,127) and chr(event.keyval) or None
42 global _trigger_set, _result_file_path, _got_trigger 42 global _trigger_set, _result_file_path, _got_trigger
43 if ('GDK_CONTROL_MASK' not in event.state.value_names 43 if ('GDK_CONTROL_MASK' not in event.state.value_names
44 or event.keyval not in _trigger_set): 44 or event.keyval not in _trigger_set):
45 return False 45 return False
46 XXX_log('got test switch trigger %s(%s)' % (event.keyval, char)) 46 XXX_log('got test switch trigger %s(%s)' % (event.keyval, char))
47 _got_trigger = char 47 _got_trigger = char
48 gtk.main_quit() 48 gtk.main_quit()
49 return True 49 return True
50 50
51 51
52 def run_test_widget(test_widget=None, test_widget_size=None, 52 def run_test_widget(test_widget=None, test_widget_size=None,
53 window_registration_callback=None): 53 invisible_cursor=True,
54 window_registration_callback=None,
55 cleanup_callback=None):
56
54 window = gtk.Window(gtk.WINDOW_TOPLEVEL) 57 window = gtk.Window(gtk.WINDOW_TOPLEVEL)
55 window.connect('destroy', lambda _: gtk.main_quit())
56 window.modify_bg(gtk.STATE_NORMAL, _BLACK) 58 window.modify_bg(gtk.STATE_NORMAL, _BLACK)
57 window.set_size_request(*test_widget_size) 59 window.set_size_request(*test_widget_size)
58 60
59 align = gtk.Alignment(xalign=0.5, yalign=0.5) 61 align = gtk.Alignment(xalign=0.5, yalign=0.5)
60 align.add(test_widget) 62 align.add(test_widget)
61 63
62 window.add(align) 64 window.add(align)
63 window.show_all() 65 window.show_all()
64 66
65 gtk.gdk.pointer_grab(window.window, confine_to=window.window) 67 gtk.gdk.pointer_grab(window.window, confine_to=window.window)
66 gtk.gdk.keyboard_grab(window.window) 68 gtk.gdk.keyboard_grab(window.window)
67 69
68 # create and use an invisible cursor 70 if invisible_cursor:
69 pixmap = gtk.gdk.Pixmap(None, 1, 1, 1) 71 pixmap = gtk.gdk.Pixmap(None, 1, 1, 1)
70 color = gtk.gdk.Color() 72 color = gtk.gdk.Color()
71 cursor = gtk.gdk.Cursor(pixmap, pixmap, color, color, 0, 0) 73 cursor = gtk.gdk.Cursor(pixmap, pixmap, color, color, 0, 0)
72 window.window.set_cursor(cursor) 74 window.window.set_cursor(cursor)
73 75
74 if window_registration_callback is not None: 76 if window_registration_callback is not None:
75 window_registration_callback(window) 77 window_registration_callback(window)
76 78
77 XXX_log('factory_test running gtk.main') 79 XXX_log('factory_test running gtk.main')
78 gtk.main() 80 gtk.main()
79 XXX_log('factory_test quit gtk.main') 81 XXX_log('factory_test quit gtk.main')
80 82
83 if cleanup_callback is not None:
84 cleanup_callback()
85
81 gtk.gdk.pointer_ungrab() 86 gtk.gdk.pointer_ungrab()
82 gtk.gdk.keyboard_ungrab() 87 gtk.gdk.keyboard_ungrab()
83 88
84 global _got_trigger 89 global _got_trigger
85 if _got_trigger is None: 90 if _got_trigger is None:
86 return 91 return
87 with open(_result_file_path, 'w') as file: 92 with open(_result_file_path, 'w') as file:
88 file.write('%s\n' % repr(_got_trigger)) 93 file.write('%s\n' % repr(_got_trigger))
89 raise error.TestFail('explicit test switch triggered (%s)' % _got_trigger) 94 raise error.TestFail('explicit test switch triggered (%s)' % _got_trigger)
OLDNEW
« no previous file with comments | « no previous file | client/deps/factory/startx.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698