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

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

Powered by Google App Engine
This is Rietveld 408576698