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

Side by Side Diff: client/bin/factory_ui_lib.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 ('k') | client/common_lib/factory_test.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.bin import factory
17 from autotest_lib.client.common_lib import error
18
19 import gtk
20 import sys
21
22
23 BLACK = gtk.gdk.Color()
24 RED = gtk.gdk.Color(0xFFFF, 0, 0)
25 GREEN = gtk.gdk.Color(0, 0xFFFF, 0)
26 BLUE = gtk.gdk.Color(0, 0, 0xFFFF)
27 WHITE = gtk.gdk.Color(0xFFFF, 0xFFFF, 0xFFFF)
28
29 LIGHT_GREEN = gtk.gdk.color_parse('light green')
30
31 ACTIVE = 'ACTIVE'
32 PASSED = 'PASS'
33 FAILED = 'FAIL'
34 UNTESTED = 'UNTESTED'
35
36 STATUS_CODE_MAP = {
37 'START': ACTIVE,
38 'GOOD': PASSED,
39 'FAIL': FAILED,
40 'ERROR': FAILED}
41
42 LABEL_COLORS = {
43 ACTIVE: gtk.gdk.color_parse('light goldenrod'),
44 PASSED: gtk.gdk.color_parse('pale green'),
45 FAILED: gtk.gdk.color_parse('tomato'),
46 UNTESTED: gtk.gdk.color_parse('dark slate grey')}
47
48
49 class State:
50
51 def __init__(self, trigger_set=set(), result_file_path=None):
52 self._got_trigger = None
53 self._result_file_path = result_file_path
54 self._trigger_set = [ord(x) for x in trigger_set]
55
56 def exit_on_trigger(self, event):
57 char = event.keyval in range(32,127) and chr(event.keyval) or None
58 if ('GDK_CONTROL_MASK' not in event.state.value_names
59 or event.keyval not in self._trigger_set):
60 return False
61 factory.log('got test switch trigger %s(%s)' % (event.keyval, char))
62 self._got_trigger = char
63 gtk.main_quit()
64 return True
65
66 def run_test_widget(self,
67 test_widget=None,
68 test_widget_size=None,
69 invisible_cursor=True,
70 window_registration_callback=None,
71 cleanup_callback=None):
72
73 window = gtk.Window(gtk.WINDOW_TOPLEVEL)
74 window.modify_bg(gtk.STATE_NORMAL, BLACK)
75 window.set_size_request(*test_widget_size)
76
77 align = gtk.Alignment(xalign=0.5, yalign=0.5)
78 align.add(test_widget)
79
80 window.add(align)
81 window.show_all()
82
83 gtk.gdk.pointer_grab(window.window, confine_to=window.window)
84 gtk.gdk.keyboard_grab(window.window)
85
86 if invisible_cursor:
87 pixmap = gtk.gdk.Pixmap(None, 1, 1, 1)
88 color = gtk.gdk.Color()
89 cursor = gtk.gdk.Cursor(pixmap, pixmap, color, color, 0, 0)
90 window.window.set_cursor(cursor)
91
92 if window_registration_callback is not None:
93 window_registration_callback(window)
94
95 factory.log('factory_test running gtk.main')
96 gtk.main()
97 factory.log('factory_test quit gtk.main')
98
99 if cleanup_callback is not None:
100 cleanup_callback()
101
102 gtk.gdk.pointer_ungrab()
103 gtk.gdk.keyboard_ungrab()
104
105 if self._got_trigger is None:
106 return
107 with open(self._result_file_path, 'w') as file:
108 file.write('%s\n' % repr(self._got_trigger))
109 raise error.TestFail('explicit test switch triggered (%s)' %
110 self._got_trigger)
OLDNEW
« no previous file with comments | « client/bin/factory_ui ('k') | client/common_lib/factory_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698