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

Side by Side Diff: client/site_tests/factory_ExternalStorage/factory_ExternalStorage.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 # This is a factory test to test external SD and USB ports. 10 # This is a factory test to test external SD and USB ports.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 lssys = utils.run('ls -d /sys/block/sd*') 47 lssys = utils.run('ls -d /sys/block/sd*')
48 devices = lssys.stdout.rsplit('\n') 48 devices = lssys.stdout.rsplit('\n')
49 new_devices = set(os.path.basename(d.rstrip()) for d in devices if d) 49 new_devices = set(os.path.basename(d.rstrip()) for d in devices if d)
50 return new_devices 50 return new_devices
51 51
52 52
53 class factory_ExternalStorage(test.test): 53 class factory_ExternalStorage(test.test):
54 version = 1 54 version = 1
55 preserve_srcdir = True 55 preserve_srcdir = True
56 56
57 def key_release_callback(self, widget, event):
58 char = event.keyval in range(32,127) and chr(event.keyval) or None
59 factory.log('key_release_callback %s(%s)' %
60 (event.keyval, char))
61 self._ft_state.exit_on_trigger(event)
62 return True
63
64 def expose_event(self, widget, event): 57 def expose_event(self, widget, event):
65 context = widget.window.cairo_create() 58 context = widget.window.cairo_create()
66 context.set_source_surface(self._image, 0, 0) 59 context.set_source_surface(self._image, 0, 0)
67 context.paint() 60 context.paint()
68 return True 61 return True
69 62
70 def register_callbacks(self, window):
71 window.connect('key-release-event', self.key_release_callback)
72 window.add_events(gtk.gdk.KEY_RELEASE_MASK)
73
74 def rescan_storage(self, subtest_tag): 63 def rescan_storage(self, subtest_tag):
75 if self._state == _STATE_WAIT_INSERT: 64 if self._state == _STATE_WAIT_INSERT:
76 new_devices = find_all_storage_dev() 65 new_devices = find_all_storage_dev()
77 diff = new_devices - self._devices 66 diff = new_devices - self._devices
78 if diff: 67 if diff:
79 self._devices = new_devices 68 self._devices = new_devices
80 factory.log('found new devs : %s' % diff) 69 factory.log('found new devs : %s' % diff)
81 self._target_device = diff.pop() 70 self._target_device = diff.pop()
82 devpath = '/dev/%s' % self._target_device 71 devpath = '/dev/%s' % self._target_device
83 self._prompt.set_text(_TESTING_FMT_STR(devpath)) 72 self._prompt.set_text(_TESTING_FMT_STR(devpath))
(...skipping 14 matching lines...) Expand all
98 self._error += _ERR_TOO_MANY_REMOVE_FMT_STR( 87 self._error += _ERR_TOO_MANY_REMOVE_FMT_STR(
99 self._target_device, diff) 88 self._target_device, diff)
100 if diff and self._target_device not in diff: 89 if diff and self._target_device not in diff:
101 self._error += _ERR_DEV_NOT_REMOVE_FMT_STR( 90 self._error += _ERR_DEV_NOT_REMOVE_FMT_STR(
102 self._target_device) 91 self._target_device)
103 if diff: 92 if diff:
104 gtk.main_quit() 93 gtk.main_quit()
105 return True 94 return True
106 95
107 def run_once(self, 96 def run_once(self,
108 test_widget_size=None,
109 trigger_set=None,
110 subtest_tag=None, 97 subtest_tag=None,
111 media=None): 98 media=None):
112 99
113 factory.log('%s run_once' % self.__class__) 100 factory.log('%s run_once' % self.__class__)
114 101
115 self._error = '' 102 self._error = ''
116 103
117 os.chdir(self.srcdir) 104 os.chdir(self.srcdir)
118 105
119 self._media = media 106 self._media = media
120 factory.log('media = %s' % media) 107 factory.log('media = %s' % media)
121 108
122 self.insertion_image = cairo.ImageSurface.create_from_png( 109 self.insertion_image = cairo.ImageSurface.create_from_png(
123 '%s_insert.png' % media) 110 '%s_insert.png' % media)
124 self.removal_image = cairo.ImageSurface.create_from_png( 111 self.removal_image = cairo.ImageSurface.create_from_png(
125 '%s_remove.png' % media) 112 '%s_remove.png' % media)
126 self.testing_image = cairo.ImageSurface.create_from_png( 113 self.testing_image = cairo.ImageSurface.create_from_png(
127 '%s_testing.png' % media) 114 '%s_testing.png' % media)
128 115
129 image_size_set = set([(i.get_width(), i.get_height()) for 116 image_size_set = set([(i.get_width(), i.get_height()) for
130 i in [self.insertion_image, 117 i in [self.insertion_image,
131 self.removal_image, 118 self.removal_image,
132 self.testing_image]]) 119 self.testing_image]])
133 assert len(image_size_set) == 1 120 assert len(image_size_set) == 1
134 image_size = image_size_set.pop() 121 image_size = image_size_set.pop()
135 122
136 factory.log('subtest_tag = %s' % subtest_tag) 123 factory.log('subtest_tag = %s' % subtest_tag)
137 124
138 self._ft_state = ful.State(trigger_set)
139
140 label = gtk.Label('') 125 label = gtk.Label('')
141 label.modify_font(pango.FontDescription('courier new condensed 20')) 126 label.modify_font(pango.FontDescription('courier new condensed 20'))
142 label.set_alignment(0.5, 0.5) 127 label.set_alignment(0.5, 0.5)
143 label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('light green')) 128 label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse('light green'))
144 self._prompt = label 129 self._prompt = label
145 130
146 self._prompt.set_text(_INSERT_FMT_STR(self._media)) 131 self._prompt.set_text(_INSERT_FMT_STR(self._media))
147 self._state = _STATE_WAIT_INSERT 132 self._state = _STATE_WAIT_INSERT
148 self._image = self.insertion_image 133 self._image = self.insertion_image
149 self._result = False 134 self._result = False
150 self._devices = find_all_storage_dev() 135 self._devices = find_all_storage_dev()
151 gobject.timeout_add(250, self.rescan_storage, subtest_tag) 136 gobject.timeout_add(250, self.rescan_storage, subtest_tag)
152 137
153 drawing_area = gtk.DrawingArea() 138 drawing_area = gtk.DrawingArea()
154 drawing_area.set_size_request(*image_size) 139 drawing_area.set_size_request(*image_size)
155 drawing_area.connect('expose_event', self.expose_event) 140 drawing_area.connect('expose_event', self.expose_event)
156 self._pictogram = drawing_area 141 self._pictogram = drawing_area
157 142
158 vbox = gtk.VBox() 143 vbox = gtk.VBox()
159 vbox.pack_start(drawing_area, False, False) 144 vbox.pack_start(drawing_area, False, False)
160 vbox.pack_start(label, False, False) 145 vbox.pack_start(label, False, False)
161 146
162 test_widget = gtk.EventBox() 147 test_widget = gtk.EventBox()
163 test_widget.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('black')) 148 test_widget.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('black'))
164 test_widget.add(vbox) 149 test_widget.add(vbox)
165 150
166 self._ft_state.run_test_widget( 151 ful.run_test_widget(self.job, test_widget)
167 test_widget=test_widget,
168 test_widget_size=test_widget_size,
169 window_registration_callback=self.register_callbacks)
170 152
171 if self._error: 153 if self._error:
172 raise error.TestFail(self._error) 154 raise error.TestFail(self._error)
173 155
174 factory.log('%s run_once finished' % self.__class__) 156 factory.log('%s run_once finished' % self.__class__)
OLDNEW
« no previous file with comments | « client/site_tests/factory_ExtDisplay/factory_ExtDisplay.py ('k') | client/site_tests/factory_Keyboard/factory_Keyboard.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698