blob: 21ad856fcf7ac6089584f7ba7b828009c5da0aeb [file] [log] [blame]
# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
from autotest_lib.client.bin import test
from autotest_lib.client.bin import utils
class touch_playback_test_base(test.test):
"""Base class for touch tests involving playback."""
version = 1
_PLAYBACK_COMMAND = 'evemu-play --insert-slot0 %s < %s'
_INPUTCONTROL = '/opt/google/input/inputcontrol'
_TOUCH_TYPES = ['touchpad', 'touchscreen']
def _has_touchpad(self):
"""True if device under test has a touchpad; else False."""
return self._has_inputs['touchpad']
def _has_touchscreen(self):
"""True if device under test has a touchscreen; else False."""
return self._has_inputs['touchscreen']
def warmup(self):
"""Determine the nodes of all present touch devices, if any.
Use inputcontrol command to get the touch ids and xinput to get the
corresponding node numbers. These numbers are used for playback.
name_cmd = '%s --names -t %s' % (self._INPUTCONTROL, '%s')
type_cmd = '%s | cut -d : -f 1' % name_cmd
node_cmd = ('DISPLAY=:0 XAUTHORITY=/home/chronos/.Xauthority '
'xinput list-props %s '
'| grep dev/input | cut -d \'"\' -f 2')
self._has_inputs = {}
self._nodes = {}
for input_type in self._TOUCH_TYPES:
id_num = % input_type).stdout.strip()
if id_num:
self._has_inputs[input_type] = True
self._nodes[input_type] =
node_cmd % id_num).stdout.strip()
name = % input_type).stdout.strip()'Found %s named %s at node %s', input_type,
name, self._nodes[input_type])
self._has_inputs[input_type] = False
self._nodes[input_type] = None
def _playback(self, filepath, touch_type='touchpad'):
"""Playback a given set of touch movements.
@param filepath: path to the movements file on the DUT.
@param use_touchpad: true to use touchpad, false for touchscreen.
assert(touch_type in self._TOUCH_TYPES)
node = self._nodes[touch_type]'Playing back finger-movement on %s, file=%s.', node,
filepath) % (node, filepath))
def _set_australian_scrolling(self, value):
"""Set australian scrolling to the given value.
@param value: True for enabled, False for disabled.
cmd_value = 1 if value else 0'%s --australian_scrolling %d' % (self._INPUTCONTROL,
cmd_value))'Australian scrolling turned %s.',
'on' if value else 'off')