| OLD | NEW |
| 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 import os, random, re, shutil, time | 5 import os, random, re, shutil, time |
| 6 from autotest_lib.client.bin import site_ui_test, site_utils, test, utils | 6 from autotest_lib.client.bin import site_ui_test, site_utils, test, utils |
| 7 from autotest_lib.client.common_lib import error | 7 from autotest_lib.client.common_lib import error |
| 8 | 8 |
| 9 class desktopui_WindowManagerHotkeys(site_ui_test.UITest): | 9 class desktopui_WindowManagerHotkeys(site_ui_test.UITest): |
| 10 version = 1 | 10 version = 1 |
| 11 | 11 |
| 12 def __get_channel_volume(self, output, channel_name): | |
| 13 """Find a channel's volume within the amixer command's output. | |
| 14 | |
| 15 Helper method used by __get_mixer_volume(). | |
| 16 | |
| 17 Args: | |
| 18 output: str output from "amixer get Master" | |
| 19 channel_name: str name of channel, e.g. "Front Left" | |
| 20 | |
| 21 Returns: | |
| 22 Channel volume as an int (0 is returned for muted channels). | |
| 23 """ | |
| 24 regexp = '%s: Playback \d+ \[(\d+)%%\] \[(on|off)\]' % channel_name | |
| 25 match = re.search(regexp, output) | |
| 26 if not match: | |
| 27 raise error.TestError( | |
| 28 'Unable to get volume for channel "%s"' % channel_name) | |
| 29 if match.group(2) == 'off': | |
| 30 return 0 | |
| 31 return int(match.group(1)) | |
| 32 | |
| 33 def __get_mixer_volume(self): | |
| 34 """Get the current mixer volume. | |
| 35 | |
| 36 Returns: | |
| 37 A two-element tuple consisting of the int volume of the left and | |
| 38 right channels. | |
| 39 """ | |
| 40 output = utils.system_output('/usr/bin/amixer get Master') | |
| 41 return (self.__get_channel_volume(output, 'Front Left'), | |
| 42 self.__get_channel_volume(output, 'Front Right')) | |
| 43 | |
| 44 def run_once(self): | 12 def run_once(self): |
| 45 ax = self.get_autox() | 13 ax = self.get_autox() |
| 46 | 14 |
| 47 # Start a terminal and wait for it to get the focus. | 15 # Start a terminal and wait for it to get the focus. |
| 48 # TODO: This is a bit of a hack. To watch for the terminal getting | 16 orig_active_win_xid = ax.get_active_window_property() |
| 49 # the focus, we create a new window, wait for it to get the focus, | |
| 50 # and then launch the terminal and wait for our window to lose the | |
| 51 # focus (AutoX isn't notified about focus events on the terminal | |
| 52 # window itself). It's maybe cleaner to add a method to AutoX to | |
| 53 # get the currently-focused window and then just poll that after | |
| 54 # starting the terminal until it changes. | |
| 55 win = ax.create_and_map_window() | |
| 56 info = ax.get_window_info(win.id) | |
| 57 ax.await_condition( | |
| 58 lambda: info.is_focused, | |
| 59 desc='Waiting for window to get focus') | |
| 60 ax.send_hotkey('Ctrl-Alt-t') | 17 ax.send_hotkey('Ctrl-Alt-t') |
| 61 ax.await_condition( | 18 ax.await_condition( |
| 62 lambda: not info.is_focused, | 19 lambda: ax.get_active_window_property() != orig_active_win_xid, |
| 63 desc='Waiting for window to lose focus') | 20 desc='Waiting for terminal to become active window') |
| 64 | |
| 65 # Type in it to create a file in /tmp and exit. | |
| 66 temp_filename = '/tmp/desktopup_WindowManagerHotkeys_%d' % time.time() | |
| 67 ax.send_text('touch %s\n' % temp_filename) | |
| 68 ax.send_text('exit\n') | |
| 69 site_utils.poll_for_condition( | |
| 70 lambda: os.access(temp_filename, os.F_OK), | |
| 71 error.TestFail( | |
| 72 'Waiting for %s to be created from terminal' % temp_filename)) | |
| 73 os.remove(temp_filename) | |
| 74 | 21 |
| 75 # Press the Print Screen key and check that a screenshot is written. | 22 # Press the Print Screen key and check that a screenshot is written. |
| 76 screenshot_dir = '/home/chronos/user/Downloads/Screenshots' | 23 screenshot_dir = '/home/chronos/user/Downloads/Screenshots' |
| 77 shutil.rmtree(screenshot_dir, ignore_errors=True) | 24 shutil.rmtree(screenshot_dir, ignore_errors=True) |
| 78 ax.send_hotkey('Print') | 25 ax.send_hotkey('Print') |
| 79 site_utils.poll_for_condition( | 26 site_utils.poll_for_condition( |
| 80 lambda: os.access(screenshot_dir, os.F_OK) and \ | 27 lambda: os.access(screenshot_dir, os.F_OK) and \ |
| 81 os.listdir(screenshot_dir), | 28 os.listdir(screenshot_dir), |
| 82 error.TestFail( | 29 error.TestFail( |
| 83 'Waiting for screenshot in %s' % screenshot_dir)) | 30 'Waiting for screenshot in %s' % screenshot_dir)) |
| 84 shutil.rmtree(screenshot_dir, ignore_errors=True) | 31 shutil.rmtree(screenshot_dir, ignore_errors=True) |
| 85 | |
| 86 # Make sure that the mixer is unmuted and at 50% before we test the | |
| 87 # audio key bindings. | |
| 88 utils.system('/usr/bin/amixer sset Master unmute 50%') | |
| 89 | |
| 90 ax.send_hotkey('XF86AudioRaiseVolume') | |
| 91 site_utils.poll_for_condition( | |
| 92 lambda: self.__get_mixer_volume() == (55, 55), | |
| 93 error.TestFail('Waiting for volume to be increased')) | |
| 94 | |
| 95 ax.send_hotkey('XF86AudioLowerVolume') | |
| 96 site_utils.poll_for_condition( | |
| 97 lambda: self.__get_mixer_volume() == (50, 50), | |
| 98 error.TestFail('Waiting for volume to be decreased')) | |
| 99 | |
| 100 ax.send_hotkey('XF86AudioMute') | |
| 101 site_utils.poll_for_condition( | |
| 102 lambda: self.__get_mixer_volume() == (0, 0), | |
| 103 error.TestFail('Waiting for volume to be muted')) | |
| 104 | |
| 105 ax.send_hotkey('XF86AudioRaiseVolume') | |
| 106 site_utils.poll_for_condition( | |
| 107 lambda: self.__get_mixer_volume() == (55, 55), | |
| 108 error.TestFail('Waiting for volume to be increased')) | |
| OLD | NEW |