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

Unified Diff: client/site_tests/factory_Audio/factory_Audio.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, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « client/deps/factory/startx.sh ('k') | client/site_tests/factory_Camera/factory_Camera.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/site_tests/factory_Audio/factory_Audio.py
diff --git a/client/site_tests/factory_Audio/factory_Audio.py b/client/site_tests/factory_Audio/factory_Audio.py
index 41398a9c0dd3669bf0393c4b49f74646afacd00e..afe77dc3277b3cc4ede22e91d4477f398ee5e331 100644
--- a/client/site_tests/factory_Audio/factory_Audio.py
+++ b/client/site_tests/factory_Audio/factory_Audio.py
@@ -33,63 +33,45 @@ _SAMPLE_LIST = ['Headset Audio Test', 'Built-in Audio Test']
_VERBOSE = False
-# FIXME: tbroch : refactor from factory_ui -> factory_ui_lib.py
-_SEP_COLOR = gtk.gdk.color_parse('grey50')
-def make_vsep(width=1):
- frame = gtk.EventBox()
- frame.set_size_request(width, -1)
- frame.modify_bg(gtk.STATE_NORMAL, _SEP_COLOR)
- return frame
-
-def make_hsep(width=1):
- frame = gtk.EventBox()
- frame.set_size_request(-1, width)
- frame.modify_bg(gtk.STATE_NORMAL, _SEP_COLOR)
- return frame
-
-
class factory_Audio(test.test):
version = 1
-
def audio_subtest_widget(self, name):
- window = gtk.Window(gtk.WINDOW_TOPLEVEL)
- screen = window.get_screen()
- screen_size = (screen.get_width(), screen.get_height())
- window.set_size_request(*self._test_widget_size)
-
vb = gtk.VBox()
ebh = gtk.EventBox()
ebh.modify_bg(gtk.STATE_NORMAL, ful.LABEL_COLORS[ful.ACTIVE])
ebh.add(ful.make_label(name, size=_LABEL_BIG_SIZE,
fg=ful.BLACK))
vb.pack_start(ebh)
- vb.pack_start(make_vsep(3), False, False)
+ vb.pack_start(ful.make_vsep(3), False, False)
if re.search('Headset', name):
lab_str = 'Connect headset to device\n將耳機接上音源孔'
else:
lab_str = 'Remove headset from device\n將耳機移開音源孔'
vb.pack_start(ful.make_label(lab_str, fg=ful.WHITE))
- vb.pack_start(make_vsep(3), False, False)
+ vb.pack_start(ful.make_vsep(3), False, False)
vb.pack_start(ful.make_label(\
'Press & hold \'r\' to record\n壓住 \'r\' 鍵開始錄音\n' + \
'[Playback will follow]\n[之後會重播錄到的聲音]\n\n' + \
'Press & hold \'p\' to play sample\n' + \
'壓住 \'p\' 鍵以播放範例'))
- vb.pack_start(make_vsep(3), False, False)
+ vb.pack_start(ful.make_vsep(3), False, False)
vb.pack_start(ful.make_label(ful.USER_PASS_FAIL_SELECT_STR,
fg=ful.WHITE))
- # need event box to effect bg color
+ # Need event box to effect bg color.
eb = gtk.EventBox()
eb.modify_bg(gtk.STATE_NORMAL, ful.BLACK)
eb.add(vb)
- window.add(eb)
- window.show_all()
- self._fs_window = window
+
+ self._subtest_widget = eb
+
+ self._test_widget.remove(self._top_level_test_list)
+ self._test_widget.add(self._subtest_widget)
+ self._test_widget.show_all()
def close_bgjob(self, sample_name):
- job = self._job
+ job = self._bg_job
if job:
utils.nuke_subprocess(job.sp)
utils.join_bg_jobs([job], timeout=1)
@@ -98,7 +80,7 @@ class factory_Audio(test.test):
raise error.CmdError(
sample_name, result,
'stdout: %s\nstderr: %s' % (result.stdout, result.stderr))
- self._job = None
+ self._bg_job = None
def goto_next_sample(self):
if not self._sample_queue:
@@ -110,28 +92,30 @@ class factory_Audio(test.test):
def cleanup_sample(self):
factory.log('Inside cleanup_sample')
- self._fs_window.destroy()
- self._fs_window = None
+ self._test_widget.remove(self._subtest_widget)
+ self._subtest_widget = None
+ self._test_widget.add(self._top_level_test_list)
+ self._test_widget.show_all()
self.goto_next_sample()
def key_press_callback(self, widget, event):
name = self._current_sample
- if event.keyval == gtk.keysyms.space and not self._fs_window:
- # start the subtest
+ if (event.keyval == gtk.keysyms.space and self._subtest_widget is None):
+ # Start subtest.
self.audio_subtest_widget(name)
else:
self.close_bgjob(name)
cmd = None
if event.keyval == ord('r'):
- # record via mic
+ # Record via mic.
if os.path.isfile('rec.wav'):
os.unlink('rec.wav')
cmd = 'arecord -f dat -t wav rec.wav'
elif event.keyval == ord('p'):
- # playback canned audio
- cmd = 'aplay %s' % self._sample
+ # Playback canned audio.
+ cmd = 'aplay %s' % self._audio_sample_path
if cmd:
- self._job = utils.BgJob(cmd, stderr_level=logging.DEBUG)
+ self._bg_job = utils.BgJob(cmd, stderr_level=logging.DEBUG)
factory.log("cmd: " + cmd)
self._test_widget.queue_draw()
return True
@@ -149,13 +133,10 @@ class factory_Audio(test.test):
elif event.keyval == ord('r'):
self.close_bgjob(name)
cmd = 'aplay rec.wav'
- self._job = utils.BgJob(cmd, stderr_level=logging.DEBUG)
+ self._bg_job = utils.BgJob(cmd, stderr_level=logging.DEBUG)
factory.log("cmd: " + cmd)
elif event.keyval == ord('p'):
self.close_bgjob(name)
- else:
- self._ft_state.exit_on_trigger(event)
-
self._test_widget.queue_draw()
return True
@@ -187,61 +168,47 @@ class factory_Audio(test.test):
window.connect('key-release-event', self.key_release_callback)
window.add_events(gtk.gdk.KEY_RELEASE_MASK)
- def locate_asample(self, sample):
- if not sample:
+ def locate_audio_sample(self, path):
+ if path is None:
raise error.TestFail('ERROR: Must provide an audio sample')
- if not os.path.isabs(sample):
- # assume its in deps
- sample = self.autodir + '/' + sample
- if not os.path.exists(sample):
- raise error.TestFail('ERROR: Unable to find audio sample %s' \
- % sample)
- self._sample=sample
-
- def run_once(self,
- test_widget_size=None,
- trigger_set=None,
- sample=None,
- ):
+ if not os.path.isabs(path):
+ # Assume rel-path samples are in deps/factory.
+ path = self.job.autodir + '/deps/factory/' + path
+ if not os.path.exists(path):
+ raise error.TestFail('ERROR: Unable to find audio sample %s' % path)
+ return path
+
+ def run_once(self, audio_sample_path=None):
factory.log('%s run_once' % self.__class__)
- self._job = None
- self._test_widget_size = test_widget_size
- self.locate_asample(sample)
- # to write the recordings
+ # Write recordings in tmpdir.
os.chdir(self.tmpdir)
- xset_status = os.system('LD_LIBRARY_PATH=/usr/local/lib xset r off')
- if xset_status:
- raise error.TestFail('ERROR: disabling key repeat')
-
- self._ft_state = ful.State(trigger_set=trigger_set)
+ self._bg_job = None
+ self._audio_sample_path = self.locate_audio_sample(audio_sample_path)
self._sample_queue = [x for x in reversed(_SAMPLE_LIST)]
self._status_map = dict((n, ful.UNTESTED) for n in _SAMPLE_LIST)
prompt_label = ful.make_label(_LABEL_START_STR, alignment=(0.5, 0.5))
- vbox = gtk.VBox()
- vbox.pack_start(prompt_label, False, False)
+ self._top_level_test_list = gtk.VBox()
+ self._top_level_test_list.pack_start(prompt_label, False, False)
for name in _SAMPLE_LIST:
label_box = self.make_sample_label_box(name)
- vbox.pack_start(label_box, False, False)
+ self._top_level_test_list.pack_start(label_box, False, False)
- test_widget = gtk.EventBox()
- test_widget.modify_bg(gtk.STATE_NORMAL, ful.BLACK)
- test_widget.add(vbox)
- self._test_widget = test_widget
+ self._test_widget = gtk.EventBox()
+ self._test_widget.modify_bg(gtk.STATE_NORMAL, ful.BLACK)
+ self._test_widget.add(self._top_level_test_list)
- self.goto_next_sample()
+ self._subtest_widget = None
- self._fs_window = None
+ self.goto_next_sample()
- self._ft_state.run_test_widget(
- test_widget=test_widget,
- test_widget_size=test_widget_size,
+ ful.run_test_widget(self.job, self._test_widget,
window_registration_callback=self.register_callbacks)
failed_set = set(name for name, status in self._status_map.items()
« no previous file with comments | « client/deps/factory/startx.sh ('k') | client/site_tests/factory_Camera/factory_Camera.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698